| 8267 | */ |
| 8268 | |
| 8269 | static double apply_selectivity_for_table(JOIN_TAB *s, |
| 8270 | uint use_cond_selectivity) |
| 8271 | { |
| 8272 | double dbl_records; |
| 8273 | |
| 8274 | if (use_cond_selectivity > 1) |
| 8275 | { |
| 8276 | TABLE *table= s->table; |
| 8277 | double sel= table->cond_selectivity; |
| 8278 | double table_records= rows2double(s->records); |
| 8279 | DBUG_ASSERT(sel >= 0 && sel <= 1.0); |
| 8280 | /* |
| 8281 | table->cond_selectivity will include data from opt_range. |
| 8282 | Here we check that this is indeed the case. |
| 8283 | Note that if table_records == 0, then 'sel' is probably 1 |
| 8284 | */ |
| 8285 | DBUG_ASSERT(table_records == 0 || |
| 8286 | sel <= s->table->opt_range_condition_rows / |
| 8287 | table_records); |
| 8288 | dbl_records= table_records * sel; |
| 8289 | } |
| 8290 | else |
| 8291 | { |
| 8292 | /* |
| 8293 | This is only taking into considering constant key parts used with |
| 8294 | this table! |
| 8295 | If no such conditions existed the following should normally hold: |
| 8296 | s->table->opt_range_condition_rows == s->found_rows == |
| 8297 | s->records. |
| 8298 | The case when this does not hold is when using 'best splitting' |
| 8299 | in which case s->records may be less than s->found_rows; |
| 8300 | */ |
| 8301 | DBUG_ASSERT(s->table->opt_range_condition_rows <= s->found_records); |
| 8302 | dbl_records= rows2double(MY_MIN(s->table->opt_range_condition_rows, |
| 8303 | s->records)); |
| 8304 | } |
| 8305 | |
| 8306 | DBUG_ASSERT(dbl_records <= s->records); |
| 8307 | /* |
| 8308 | Ensure we return at least one row if there is any possibility to have |
| 8309 | a matching row. Having rows >= 1.0 helps ensure that when we calculate |
| 8310 | total rows of joins, the number of resulting rows will not be less |
| 8311 | after the join. In other words, we assume there is at least one matching |
| 8312 | row when joining a row with the next table. |
| 8313 | 0.0 is returned only if it is guaranteed there are no matching rows |
| 8314 | (for example if the table is empty). |
| 8315 | */ |
| 8316 | return dbl_records ? MY_MAX(dbl_records, MIN_ROWS_AFTER_FILTERING) : 0.0; |
| 8317 | } |
| 8318 | |
| 8319 | |
| 8320 | /* |