Skip to content

Commit 84c32cd

Browse files
author
Sreeharsha Ramanavarapu
committed
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
1 parent 6ca6899 commit 84c32cd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sql/sql_select.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
22

33
This program is free software; you can redistribute it and/or modify
44
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)
74307430
{
74317431
table_map depend_map;
74327432
order->item[0]->update_used_tables();
7433-
order->depend_map=depend_map=order->item[0]->used_tables();
7433+
order->depend_map=depend_map=
7434+
order->item[0]->used_tables() & ~PARAM_TABLE_BIT;
74347435
order->used= 0;
74357436
// Not item_sum(), RAND() and no reference to table outside of sub select
74367437
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)
1558315584
DBUG_RETURN(0);
1558415585
map|=a->item[0]->used_tables();
1558515586
}
15587+
map&= ~PARAM_TABLE_BIT;
1558615588
if (!map || (map & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT)))
1558715589
DBUG_RETURN(0);
1558815590

0 commit comments

Comments
 (0)