MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:pem Date:March 28 2006 12:16pm
Subject:bk commit into 5.0 tree (pem:1.2075) BUG#16474
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of pem. When pem does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2075 06/03/28 14:16:21 pem@stripped +5 -0
  Post review fixes for BUG#16474: SP crashed MySQL.

  sql/sql_select.cc
    1.397 06/03/28 14:16:17 pem@stripped +3 -2
    Fixed comment and test for basic_const_item() instead of is_splocal().

  mysql-test/t/sp.test
    1.180 06/03/28 14:16:17 pem@stripped +5 -0
    Added reference to test case for BUG#16474.

  mysql-test/t/ps.test
    1.60 06/03/28 14:16:17 pem@stripped +34 -0
    Added test coverage for "order by" in prepared statements (related to BUG#16474).

  mysql-test/r/sp.result
    1.192 06/03/28 14:16:17 pem@stripped +6 -0
    Added reference to test case for BUG#16474.

  mysql-test/r/ps.result
    1.62 06/03/28 14:16:16 pem@stripped +46 -0
    Added test coverage for "order by" in prepared statements (related to BUG#16474).

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	pem
# Host:	pem.mysql.com
# Root:	/extern/mysql/5.0/bug16474/mysql-5.0-runtime

--- 1.396/sql/sql_select.cc	2006-03-10 14:04:51 +01:00
+++ 1.397/sql/sql_select.cc	2006-03-28 14:16:17 +02:00
@@ -12327,9 +12327,10 @@
 
   /*
     Local SP variables may be int but are expressions, not positions.
-    (And they must be fixed.)
+    (And they can't be used before fix_fields is called for them).
   */
-  if (order_item->type() == Item::INT_ITEM && !order_item->is_splocal())
+  //  if (order_item->type() == Item::INT_ITEM && !order_item->is_splocal())
+  if (order_item->type() == Item::INT_ITEM && order_item->basic_const_item())
   {						/* Order by position */
     uint count= (uint) order_item->val_int();
     if (!count || count > fields.elements)

--- 1.191/mysql-test/r/sp.result	2006-03-10 14:04:51 +01:00
+++ 1.192/mysql-test/r/sp.result	2006-03-28 14:16:17 +02:00
@@ -4885,5 +4885,11 @@
 a
 drop procedure bug16474_1|
 drop procedure bug16474_2|
+set @x = 2|
+select * from t1 order by @x|
+id	data
+c	2
+b	3
+a	1
 delete from t1|
 drop table t1,t2;

--- 1.179/mysql-test/t/sp.test	2006-03-10 14:04:51 +01:00
+++ 1.180/mysql-test/t/sp.test	2006-03-28 14:16:17 +02:00
@@ -5745,6 +5745,11 @@
 call bug16474_2(2)|
 drop procedure bug16474_1|
 drop procedure bug16474_2|
+
+# For reference: user variables are expressions too and do not affect ordering.
+set @x = 2|
+select * from t1 order by @x|
+
 delete from t1|
 
 

--- 1.61/mysql-test/r/ps.result	2006-02-27 15:51:11 +01:00
+++ 1.62/mysql-test/r/ps.result	2006-03-28 14:16:16 +02:00
@@ -880,3 +880,49 @@
 row_count()
 1
 drop table t1;
+create table t1 (a int, b int);
+insert into t1 (a,b) values (2,8),(1,9),(3,7);
+prepare stmt from "select * from t1 order by ?";
+execute stmt using @a;
+a	b
+2	8
+1	9
+3	7
+set @a=1;
+execute stmt using @a;
+a	b
+1	9
+2	8
+3	7
+set @a=2;
+execute stmt using @a;
+a	b
+3	7
+2	8
+1	9
+deallocate prepare stmt;
+select * from t1 order by 1;
+a	b
+1	9
+2	8
+3	7
+prepare stmt from "select * from t1 order by ?+1";
+set @a=0;
+execute stmt using @a;
+a	b
+2	8
+1	9
+3	7
+set @a=1;
+execute stmt using @a;
+a	b
+2	8
+1	9
+3	7
+deallocate prepare stmt;
+select * from t1 order by 1+1;
+a	b
+2	8
+1	9
+3	7
+drop table t1;

--- 1.59/mysql-test/t/ps.test	2006-02-23 22:00:01 +01:00
+++ 1.60/mysql-test/t/ps.test	2006-03-28 14:16:17 +02:00
@@ -933,4 +933,38 @@
 select row_count();
 drop table t1;
 
+#
+# BUG#16474: SP crashed MySQL
+# (when using "order by localvar", where 'localvar' is just that.
+# The actual bug test is in sp.test, this is just testing that we get the
+# expected result for prepared statements too, i.e. place holders work as
+# textual substitution. If it's a single integer, it works as the (deprecated)
+# "order by column#", otherwise it's an expression.
+#
+create table t1 (a int, b int);
+insert into t1 (a,b) values (2,8),(1,9),(3,7);
+
+# Will order by index
+prepare stmt from "select * from t1 order by ?";
+execute stmt using @a;
+set @a=1;
+execute stmt using @a;
+set @a=2;
+execute stmt using @a;
+deallocate prepare stmt;
+# For reference:
+select * from t1 order by 1;
+
+# Will not order by index.
+prepare stmt from "select * from t1 order by ?+1";
+set @a=0;
+execute stmt using @a;
+set @a=1;
+execute stmt using @a;
+deallocate prepare stmt;
+# For reference:
+select * from t1 order by 1+1;
+
+drop table t1;
+
 # End of 5.0 tests
Thread
bk commit into 5.0 tree (pem:1.2075) BUG#16474pem28 Mar