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

Function table_after_join_selectivity

sql/sql_select.cc:11267–11525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11265*/
11266
11267static
11268double table_after_join_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
11269 table_map rem_tables,
11270 double *new_records_out)
11271{
11272 uint16 ref_keyuse_steps_buf[MAX_REF_PARTS];
11273 uint ref_keyuse_size= MAX_REF_PARTS;
11274 uint16 *ref_keyuse_steps= ref_keyuse_steps_buf;
11275 Field *field;
11276 TABLE *table= s->table;
11277 MY_BITMAP *read_set= table->read_set;
11278 POSITION *pos= &join->positions[idx];
11279 double sel, records_out= pos->records_out;
11280 uint keyparts= 0;
11281 uint found_part_ref_or_null= 0;
11282
11283 if (pos->key != 0)
11284 {
11285 sel= table->cond_selectivity;
11286 /*
11287 A ref access or hash join is used for this table. ref access is created
11288 from
11289
11290 tbl.keypart1=expr1 AND tbl.keypart2=expr2 AND ...
11291
11292 and it will only return rows for which this condition is satisfied.
11293 Suppose, certain expr{i} is a constant. Since ref access only returns
11294 rows that satisfy
11295
11296 tbl.keypart{i}=const (*)
11297
11298 then selectivity of this equality should not be counted in return value
11299 of this function. This function uses the value of
11300
11301 table->cond_selectivity=selectivity(COND(tbl)) (**)
11302
11303 as a starting point. This value includes selectivity of equality (*). We
11304 should somehow discount it.
11305
11306 Looking at calculate_cond_selectivity_for_table(), one can see that
11307 the value is not necessarily a direct multiplicand in
11308 table->cond_selectivity
11309
11310 There are three possible ways to discount
11311 1. There is a potential range access on t.keypart{i}=const.
11312 (an important special case: the used ref access has a const prefix for
11313 which a range estimate is available)
11314
11315 2. The field has a histogram. field[x]->cond_selectivity has the data.
11316
11317 3. Use index stats on this index:
11318 rec_per_key[key_part+1]/rec_per_key[key_part]
11319
11320 (TODO: more details about the "t.key=othertable.col" case)
11321 */
11322 KEYUSE *keyuse= pos->key;
11323 KEYUSE *prev_ref_keyuse= keyuse;
11324 uint key= keyuse->key;

Callers 3

optimize_straight_joinFunction · 0.85

Calls 10

is_hash_join_key_noFunction · 0.85
are_tables_localFunction · 0.85
my_mallocFunction · 0.85
my_freeFunction · 0.85
bitmap_is_setFunction · 0.85
stat_recordsMethod · 0.80
is_setMethod · 0.45
used_tablesMethod · 0.45
const_itemMethod · 0.45

Tested by

no test coverage detected