| 17623 | */ |
| 17624 | |
| 17625 | static ORDER * |
| 17626 | remove_const(JOIN *join,ORDER *first_order, COND *cond, |
| 17627 | bool change_list, bool *simple_order) |
| 17628 | { |
| 17629 | /* |
| 17630 | We can't do ORDER BY using filesort if the select list contains a non |
| 17631 | deterministic value like RAND() or ROWNUM(). |
| 17632 | For example: |
| 17633 | SELECT a,ROWNUM() FROM t1 ORDER BY a; |
| 17634 | |
| 17635 | If we would first sort the table 't1', the ROWNUM() column would be |
| 17636 | generated during end_send() and the order would be wrong. |
| 17637 | |
| 17638 | Previously we had here also a test of ROLLUP: |
| 17639 | 'join->rollup.state == ROLLUP::STATE_NONE' |
| 17640 | |
| 17641 | I deleted this because the ROLLUP was never enforced because of a |
| 17642 | bug where the inital value of simple_order was ignored. Having |
| 17643 | ROLLUP tested now when the code is fixed, causes many test failure |
| 17644 | and some wrong results so better to leave the code as it was |
| 17645 | related to ROLLUP. |
| 17646 | */ |
| 17647 | *simple_order= !join->select_lex->rownum_in_field_list; |
| 17648 | if (join->only_const_tables()) |
| 17649 | return change_list ? 0 : first_order; // No need to sort |
| 17650 | |
| 17651 | ORDER *order,**prev_ptr, *tmp_order; |
| 17652 | table_map UNINIT_VAR(first_table); /* protected by first_is_base_table */ |
| 17653 | table_map not_const_tables= ~join->const_table_map; |
| 17654 | table_map ref; |
| 17655 | bool first_is_base_table= FALSE; |
| 17656 | DBUG_ENTER("remove_const"); |
| 17657 | |
| 17658 | /* |
| 17659 | Join tab is set after make_join_statistics() has been called. |
| 17660 | In case of one table with GROUP BY this function is called before |
| 17661 | join_tab is set for the GROUP_BY expression |
| 17662 | */ |
| 17663 | if (join->join_tab) |
| 17664 | { |
| 17665 | if (join->join_tab[join->const_tables].table) |
| 17666 | { |
| 17667 | first_table= join->join_tab[join->const_tables].table->map; |
| 17668 | first_is_base_table= TRUE; |
| 17669 | } |
| 17670 | |
| 17671 | /* |
| 17672 | Cleanup to avoid interference of calls of this function for |
| 17673 | ORDER BY and GROUP BY |
| 17674 | */ |
| 17675 | for (JOIN_TAB *tab= join->join_tab + join->const_tables; |
| 17676 | tab < join->join_tab + join->top_join_tab_count; |
| 17677 | tab++) |
| 17678 | tab->cached_eq_ref_table= FALSE; |
| 17679 | |
| 17680 | JOIN_TAB *head= join->join_tab + join->const_tables; |
| 17681 | *simple_order&= head->on_expr_ref[0] == NULL; |
| 17682 | if (*simple_order && head->table->file->ha_table_flags() & HA_SLOW_RND_POS) |
no test coverage detected