Comment 3 for bug 992942

Sergey Petrunia (sergefp) wrote :

I'm currently considering a solution where create_sort_index() would save/restore the first JOIN_TAB. It looks like this would work, except for Index Condition Pushdown:

Let's assume there is a subquery that uses filesort() on its first table.
filesort() gets its data from quick select, which uses range access, together with IndexConditionPushdown.

This subquery will execute as follows:
> filesort
     read matching records with quick select + ICP
< filesort
> do_select
  read table with rr_from_pointers(), using handler->rnd_pos() calls.
< do_select

and suppose the subquery is correlated, so we'll need to execute it multiple times.

The problem here is as follows:
 - after we've left filesort(), we need to re-initialize the table handler for making rnd_pos() calls.
 - when starting a subsequent execution, the table needs to be re-initialized for quick select with ICP.

Re-initializing for quick select is easy: we can remember the index #, and whether index_only should be ON. (Need to check also whether table->read_map should be/is re-initialized).

There is a problem with re-initialization for ICP. Pushed index condition is not saved anywhere. There is no way to remember what was pushed and re-push it later.