summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2019-12-17 21:45:53 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2019-12-17 21:45:53 +0530
commit164cf4f4631803ceac69fdf1173d7114940d29b2 (patch)
tree1eb4a1ae1f8f449f8b6a6ce81c7c1b297aff4a3e /sql/sql_select.cc
parent8129ff14407826d54745346c552fadf3d292a0d8 (diff)
downloadmariadb-git-164cf4f4631803ceac69fdf1173d7114940d29b2.tar.gz
MDEV-16579: Wrong result of query using DISTINCT COUNT(*) OVER (*)
The query requires 2 temporary tables for execution, the window function is always attached to the last temporary table, but in this case the result field of the window function points to the first temporary table rather than the last one. Fixed this by not changing window function items with temporary table items of the first temporary table.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index c9cb533aa33..33964cb270f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -23624,7 +23624,8 @@ change_to_use_tmp_fields(THD *thd, Ref_ptr_array ref_pointer_array,
for (uint i= 0; (item= it++); i++)
{
Field *field;
- if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM)
+ if ((item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) ||
+ item->with_window_func)
item_field= item;
else if (item->type() == Item::FIELD_ITEM)
item_field= item->get_tmp_table_item(thd);