List:Commits« Previous MessageNext Message »
From:kgeorge Date:July 26 2006 12:32pm
Subject:bk commit into 4.1 tree (gkodinov:1.2537) BUG#21019
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of kgeorge. When kgeorge 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@stripped, 2006-07-26 13:32:28+03:00, gkodinov@stripped +3 -0
  Bug #21019: First result of SELECT COUNT(*) different than consecutive runs
   When optimizing conditions like 'a = <some_val> OR a IS NULL' so that they're
   united into a single condition on the key and checked together the server must 
   check which value is the NULL value in a correct way : not only using ->is_null 
   but also check if the expression doesn't depend on any tables referenced in the 
   current statement. 
   This additional check must be performed because that optimization takes place 
   before the actual execution of the statement, so if the field was initialized 
   to NULL from a previous statement the optimization would be applied incorrectly.

  mysql-test/r/select.result@stripped, 2006-07-26 13:32:20+03:00, gkodinov@stripped +26 -0
    Bug #21019: First result of SELECT COUNT(*) different than consecutive runs
     - test case

  mysql-test/t/select.test@stripped, 2006-07-26 13:32:21+03:00, gkodinov@stripped +15 -0
    Bug #21019: First result of SELECT COUNT(*) different than consecutive runs
     - test case. 
       Note that ALTER TABLE is important here : it happens to
       leave the Field instance for t1.b set to NULL, witch is vital for
       demonstrating the problem fixed by this changeset.

  sql/sql_select.cc@stripped, 2006-07-26 13:32:22+03:00, gkodinov@stripped +5 -2
    Bug #21019: First result of SELECT COUNT(*) different than consecutive runs
     - check whether a value is null taking into account its table dependency.

# 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:	gkodinov
# Host:	macbook.gmz
# Root:	/Users/kgeorge/mysql/work/B21019-4.1-opt

--- 1.460/sql/sql_select.cc	2006-07-26 13:32:40 +03:00
+++ 1.461/sql/sql_select.cc	2006-07-26 13:32:40 +03:00
@@ -2143,8 +2143,11 @@ merge_key_fields(KEY_FIELD *start,KEY_FI
 	  /* field = expression OR field IS NULL */
 	  old->level= and_level;
 	  old->optimize= KEY_OPTIMIZE_REF_OR_NULL;
-	  /* Remember the NOT NULL value */
-	  if (old->val->is_null())
+	  /*
+            Remember the NOT NULL value unless the value does not depend
+            on other tables.
+          */
+	  if (!old->val->used_tables() && old->val->is_null())
 	    old->val= new_fields->val;
           /* The referred expression can be NULL: */ 
           old->null_rejecting= 0;

--- 1.75/mysql-test/r/select.result	2006-07-26 13:32:40 +03:00
+++ 1.76/mysql-test/r/select.result	2006-07-26 13:32:40 +03:00
@@ -2744,3 +2744,29 @@ SELECT i='1e+01',i=1e+01, i in (1e+01), 
 i='1e+01'	i=1e+01	i in (1e+01)	i in ('1e+01')
 0	1	1	1
 DROP TABLE t1;
+CREATE TABLE t1 (a int, b int);
+INSERT INTO t1 VALUES (1,1), (2,1), (4,10);
+CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b));
+INSERT INTO t2 VALUES (1,NULL), (2,10);
+ALTER TABLE t1 ENABLE KEYS;
+EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b
IS NULL;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index	b	b	5	NULL	2	Using index
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+a	b	a	b
+1	NULL	1	1
+1	NULL	2	1
+1	NULL	4	10
+2	10	4	10
+EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b
IS NULL;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index	b	b	5	NULL	2	Using index
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+a	b	a	b
+1	NULL	1	1
+1	NULL	2	1
+1	NULL	4	10
+2	10	4	10
+DROP TABLE IF EXISTS t1,t2;

--- 1.58/mysql-test/t/select.test	2006-07-26 13:32:40 +03:00
+++ 1.59/mysql-test/t/select.test	2006-07-26 13:32:40 +03:00
@@ -2297,4 +2297,19 @@ INSERT INTO t1 VALUES (10);
 SELECT i='1e+01',i=1e+01, i in (1e+01), i in ('1e+01') FROM t1;
 DROP TABLE t1;
 
+#
+# Bug #21019: First result of SELECT COUNT(*) different than consecutive runs
+#
+CREATE TABLE t1 (a int, b int);
+INSERT INTO t1 VALUES (1,1), (2,1), (4,10);
+
+CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b));
+INSERT INTO t2 VALUES (1,NULL), (2,10);
+ALTER TABLE t1 ENABLE KEYS;
+
+EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b
IS NULL;
+SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b
IS NULL;
+SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+DROP TABLE IF EXISTS t1,t2;
 # End of 4.1 tests
Thread
bk commit into 4.1 tree (gkodinov:1.2537) BUG#21019kgeorge26 Jul