diff options
author | Sreeharsha Ramanavarapu <sreeharsha.ramanavarapu@oracle.com> | 2017-10-19 10:19:36 +0530 |
---|---|---|
committer | Sreeharsha Ramanavarapu <sreeharsha.ramanavarapu@oracle.com> | 2017-10-19 10:19:36 +0530 |
commit | 84c32cdbe746fdabc33988fc17b1f11b08fd22e0 (patch) | |
tree | b23f2ec6dd86f1027f9f15fdaa995462eb0ae2ca | |
parent | 6ca6899683d6744b0df026b5fe01d368a8fdbf61 (diff) | |
download | mariadb-git-84c32cdbe746fdabc33988fc17b1f11b08fd22e0.tar.gz |
Bug #26867652: INCORRECT BEHAVIOR WITH PREPARE STATEMENT
AND PARAM IN ORDER BY
Issue:
------
This issue can occur when the ORDER BY list refers to a
column that contains a parameter in the select list.
Solution:
---------
In JOIN::update_depend_map and get_sort_by_table, the
ORDER BY list's used_tables isn't checked for parameters.
This can result in incorrect behavior.
This is a partial backport of Roy's
-rw-r--r-- | sql/sql_select.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 80d4b87e916..eb38d8be382 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -7430,7 +7430,8 @@ static void update_depend_map(JOIN *join, ORDER *order) { table_map depend_map; order->item[0]->update_used_tables(); - order->depend_map=depend_map=order->item[0]->used_tables(); + order->depend_map=depend_map= + order->item[0]->used_tables() & ~PARAM_TABLE_BIT; order->used= 0; // Not item_sum(), RAND() and no reference to table outside of sub select if (!(order->depend_map & (OUTER_REF_TABLE_BIT | RAND_TABLE_BIT)) @@ -15583,6 +15584,7 @@ get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables) DBUG_RETURN(0); map|=a->item[0]->used_tables(); } + map&= ~PARAM_TABLE_BIT; if (!map || (map & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT))) DBUG_RETURN(0); |