MCPcopy Create free account
hub / github.com/MariaDB/server / cost_for_index_read

Function cost_for_index_read

sql/sql_select.cc:8367–8412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8365*/
8366
8367static ALL_READ_COST cost_for_index_read(const THD *thd, const TABLE *table,
8368 uint key, ha_rows records,
8369 bool eq_ref)
8370{
8371 ALL_READ_COST cost;
8372 handler *file= table->file;
8373 ha_rows max_seeks;
8374 ha_rows extra_reads= eq_ref ? 0 : 1;
8375 DBUG_ENTER("cost_for_index_read");
8376
8377 max_seeks= (ha_rows) thd->variables.max_seeks_for_key;
8378 set_if_bigger(records, 1);
8379
8380 if (file->is_clustering_key(key))
8381 {
8382 cost.index_cost=
8383 file->ha_keyread_clustered_time(key, 1, records+extra_reads, 0);
8384 cost.copy_cost= rows2double(records) * file->ROW_COPY_COST;
8385 /* There is no 'index_only_read' with a clustered index */
8386 cost.row_cost= {0,0};
8387 /* Caping of index_blocks will happen in handler::cost() */
8388 cost.max_index_blocks= MY_MIN(file->row_blocks(), max_seeks);
8389 cost.max_row_blocks= 0;
8390 }
8391 else if (table->covering_keys.is_set(key) && !table->no_keyread)
8392 {
8393 cost.index_cost= file->ha_keyread_time(key, 1, records + extra_reads, 0);
8394 cost.row_cost= {0,0};
8395 cost.copy_cost= rows2double(records) * file->KEY_COPY_COST;
8396 cost.max_index_blocks= MY_MIN(file->index_blocks(key), max_seeks);
8397 cost.max_row_blocks= 0;
8398 }
8399 else
8400 {
8401 cost.index_cost= file->ha_keyread_time(key, 1, records + extra_reads, 0);
8402 /* ha_rnd_pos_time() includes time for copying the row */
8403 cost.row_cost= file->ha_rnd_pos_time(records);
8404 cost.max_index_blocks= MY_MIN(file->index_blocks(key), max_seeks);
8405 cost.max_row_blocks= MY_MIN(file->row_blocks(), max_seeks);
8406 cost.copy_cost= 0;
8407 }
8408 DBUG_PRINT("statistics", ("index_cost: %.3f row_cost: %.3f",
8409 file->cost(cost.index_cost),
8410 file->cost(cost.row_cost)));
8411 DBUG_RETURN(cost);
8412}
8413
8414
8415/**

Callers 2

best_access_pathFunction · 0.85

Calls 8

is_clustering_keyMethod · 0.80
ha_keyread_timeMethod · 0.80
ha_rnd_pos_timeMethod · 0.80
costMethod · 0.80
row_blocksMethod · 0.45
is_setMethod · 0.45
index_blocksMethod · 0.45

Tested by

no test coverage detected