| 28197 | */ |
| 28198 | |
| 28199 | int |
| 28200 | create_sort_index(THD *thd, JOIN *join, JOIN_TAB *tab, Filesort *fsort) |
| 28201 | { |
| 28202 | TABLE *table; |
| 28203 | SQL_SELECT *select; |
| 28204 | bool quick_created= FALSE; |
| 28205 | SORT_INFO *file_sort= 0; |
| 28206 | DBUG_ENTER("create_sort_index"); |
| 28207 | |
| 28208 | if (fsort == NULL) |
| 28209 | fsort= tab->filesort; |
| 28210 | |
| 28211 | table= tab->table; |
| 28212 | select= fsort->select; |
| 28213 | |
| 28214 | table->status=0; // May be wrong if quick_select |
| 28215 | |
| 28216 | if (!tab->preread_init_done && tab->preread_init()) |
| 28217 | goto err; |
| 28218 | |
| 28219 | // If table has a range, move it to select |
| 28220 | if (select && tab->ref.key >= 0) |
| 28221 | { |
| 28222 | if (!select->quick) |
| 28223 | { |
| 28224 | if (tab->quick) |
| 28225 | { |
| 28226 | select->quick= tab->quick; |
| 28227 | tab->quick= NULL; |
| 28228 | /* |
| 28229 | We can only use 'Only index' if quick key is same as ref_key |
| 28230 | and in index_merge 'Only index' cannot be used |
| 28231 | */ |
| 28232 | if (((uint) tab->ref.key != select->quick->index)) |
| 28233 | table->file->ha_end_keyread(); |
| 28234 | } |
| 28235 | else |
| 28236 | { |
| 28237 | /* |
| 28238 | We have a ref on a const; Change this to a range that filesort |
| 28239 | can use. |
| 28240 | For impossible ranges (like when doing a lookup on NULL on a NOT NULL |
| 28241 | field, quick will contain an empty record set. |
| 28242 | */ |
| 28243 | if (!(select->quick= (tab->type == JT_FT ? |
| 28244 | get_ft_select(thd, table, tab->ref.key) : |
| 28245 | get_quick_select_for_ref(thd, table, &tab->ref, |
| 28246 | tab->found_records)))) |
| 28247 | goto err; |
| 28248 | quick_created= TRUE; |
| 28249 | } |
| 28250 | fsort->own_select= true; |
| 28251 | } |
| 28252 | else |
| 28253 | { |
| 28254 | fsort->own_select= false; |
| 28255 | DBUG_ASSERT(tab->type == JT_REF || tab->type == JT_EQ_REF); |
| 28256 | // Update ref value |
no test coverage detected