|
1 | | -/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. |
| 1 | +/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 2 |
|
3 | 3 | This program is free software; you can redistribute it and/or modify |
4 | 4 | it under the terms of the GNU General Public License as published by |
@@ -17427,34 +17427,54 @@ static void print_join(THD *thd, |
17427 | 17427 | /* List is reversed => we should reverse it before using */ |
17428 | 17428 | List_iterator_fast<TABLE_LIST> ti(*tables); |
17429 | 17429 | TABLE_LIST **table; |
17430 | | - uint non_const_tables= 0; |
| 17430 | + |
| 17431 | + /* |
| 17432 | + If the QT_NO_DATA_EXPANSION flag is specified, we print the |
| 17433 | + original table list, including constant tables that have been |
| 17434 | + optimized away, as the constant tables may be referenced in the |
| 17435 | + expression printed by Item_field::print() when this flag is given. |
| 17436 | + Otherwise, only non-const tables are printed. |
| 17437 | + |
| 17438 | + Example: |
| 17439 | + |
| 17440 | + Original SQL: |
| 17441 | + select * from (select 1) t |
| 17442 | + |
| 17443 | + Printed without QT_NO_DATA_EXPANSION: |
| 17444 | + select '1' AS `1` from dual |
| 17445 | + |
| 17446 | + Printed with QT_NO_DATA_EXPANSION: |
| 17447 | + select `t`.`1` from (select 1 AS `1`) `t` |
| 17448 | + */ |
| 17449 | + const bool print_const_tables= (query_type & QT_NO_DATA_EXPANSION); |
| 17450 | + size_t tables_to_print= 0; |
17431 | 17451 |
|
17432 | 17452 | for (TABLE_LIST *t= ti++; t ; t= ti++) |
17433 | | - if (!t->optimized_away) |
17434 | | - non_const_tables++; |
17435 | | - if (!non_const_tables) |
| 17453 | + if (print_const_tables || !t->optimized_away) |
| 17454 | + tables_to_print++; |
| 17455 | + if (tables_to_print == 0) |
17436 | 17456 | { |
17437 | 17457 | str->append(STRING_WITH_LEN("dual")); |
17438 | 17458 | return; // all tables were optimized away |
17439 | 17459 | } |
17440 | 17460 | ti.rewind(); |
17441 | 17461 |
|
17442 | | - if (!(table= (TABLE_LIST **)thd->alloc(sizeof(TABLE_LIST*) * |
17443 | | - non_const_tables))) |
| 17462 | + if (!(table= static_cast<TABLE_LIST **>(thd->alloc(sizeof(TABLE_LIST*) * |
| 17463 | + tables_to_print)))) |
17444 | 17464 | return; // out of memory |
17445 | 17465 |
|
17446 | | - TABLE_LIST *tmp, **t= table + (non_const_tables - 1); |
| 17466 | + TABLE_LIST *tmp, **t= table + (tables_to_print - 1); |
17447 | 17467 | while ((tmp= ti++)) |
17448 | 17468 | { |
17449 | | - if (tmp->optimized_away) |
| 17469 | + if (tmp->optimized_away && !print_const_tables) |
17450 | 17470 | continue; |
17451 | 17471 | *t--= tmp; |
17452 | 17472 | } |
17453 | 17473 |
|
17454 | 17474 | DBUG_ASSERT(tables->elements >= 1); |
17455 | 17475 | (*table)->print(thd, str, query_type); |
17456 | 17476 |
|
17457 | | - TABLE_LIST **end= table + non_const_tables; |
| 17477 | + TABLE_LIST **end= table + tables_to_print; |
17458 | 17478 | for (TABLE_LIST **tbl= table + 1; tbl < end; tbl++) |
17459 | 17479 | { |
17460 | 17480 | TABLE_LIST *curr= *tbl; |
|
0 commit comments