#At file:///net/fimafeng09/export/home/tmp/oleja/mysql/mysql-5.1-telco-7.0/ based on revid:jonas@stripped
4124 Ole John Aske 2011-01-17
Updated fix for Bug#58791 'Incorrect result as Cluster may fail to reject an unpushable condition'
ha_ndbcluster::cond_push() should reject to push any condition
which refer fields outside the scope of 'this' table.
The rejection of pushing should be signaled by returning the
remaining unpushed condition - or entire 'cond' if nothing was
pushed.
Also fixes two existing bugs in ha_ndbcluster::cond_push where
we should return 'cond' instead of 'NULL' to signal that
the condition was unpushable (Due to memory alloc failure.)
@ sql/ha_ndbcluster_cond.cc
Fixed a bug in rejecting pushing of 'cond'. When a condition
is rejected, the unpushable part of the condition should be returned.
modified:
mysql-test/suite/ndb/r/ndb_condition_pushdown.result
mysql-test/suite/ndb/t/ndb_condition_pushdown.test
sql/ha_ndbcluster.cc
sql/ha_ndbcluster_cond.cc
=== modified file 'mysql-test/suite/ndb/r/ndb_condition_pushdown.result'
--- a/mysql-test/suite/ndb/r/ndb_condition_pushdown.result 2011-01-14 15:08:09 +0000
+++ b/mysql-test/suite/ndb/r/ndb_condition_pushdown.result 2011-01-17 13:29:52 +0000
@@ -2279,5 +2279,18 @@ select * from t where exists
pk i
1 3
drop table t,subq;
+create table t (pk1 int, pk2 int, primary key(pk1,pk2)) engine = ndb;
+insert into t values (1,0), (2,0), (3,0), (4,0);
+set engine_condition_pushdown=1;
+select table1.pk1, table2.pk1, table1.pk2, table2.pk2
+from t as table1, t as table2
+where table2.pk1 in (0,3) and
+(table1.pk1 = 7 or table2.pk1 = 3);
+pk1 pk1 pk2 pk2
+1 3 0 0
+2 3 0 0
+3 3 0 0
+4 3 0 0
+drop table t;
set engine_condition_pushdown = @old_ecpd;
DROP TABLE t1,t2,t3,t4,t5;
=== modified file 'mysql-test/suite/ndb/t/ndb_condition_pushdown.test'
--- a/mysql-test/suite/ndb/t/ndb_condition_pushdown.test 2011-01-14 10:42:53 +0000
+++ b/mysql-test/suite/ndb/t/ndb_condition_pushdown.test 2011-01-17 13:29:52 +0000
@@ -2346,6 +2346,28 @@ select * from t where exists
drop table t,subq;
+
+# Bug#58791 Incorrect result as Cluster may fail to reject an unpushable condition
+
+create table t (pk1 int, pk2 int, primary key(pk1,pk2)) engine = ndb;
+insert into t values (1,0), (2,0), (3,0), (4,0);
+
+set engine_condition_pushdown=1;
+
+# Multiple instances of same table (t as table<n>, ) confused
+# ha_ndbcluster::cond_push() which accepted
+# '(table1.pk1 = 7 or table2.pk1 = 3)' as a pushable cond.
+# for 'table2'
+#
+
+--sorted_result
+select table1.pk1, table2.pk1, table1.pk2, table2.pk2
+ from t as table1, t as table2
+ where table2.pk1 in (0,3) and
+ (table1.pk1 = 7 or table2.pk1 = 3);
+
+drop table t;
+
set engine_condition_pushdown = @old_ecpd;
DROP TABLE t1,t2,t3,t4,t5;
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc 2011-01-17 12:31:29 +0000
+++ b/sql/ha_ndbcluster.cc 2011-01-17 13:29:52 +0000
@@ -12785,12 +12785,24 @@ Item*
ha_ndbcluster::cond_push(const Item *cond)
{
DBUG_ENTER("cond_push");
+
+ if (cond->used_tables() & ~table->map)
+ {
+ /**
+ * 'cond' refers fields from other tables, or other instances
+ * of this table, -> reject it.
+ * (Optimizer need to have a better understanding of what is
+ * pushable by each handler.)
+ */
+ DBUG_EXECUTE("where",print_where((Item *)cond, "Rejected cond_push", QT_ORDINARY););
+ DBUG_RETURN(cond);
+ }
if (!m_cond)
m_cond= new ha_ndbcluster_cond;
if (!m_cond)
{
my_errno= HA_ERR_OUT_OF_MEM;
- DBUG_RETURN(NULL);
+ DBUG_RETURN(cond);
}
DBUG_EXECUTE("where",print_where((Item *)cond, m_tabname, QT_ORDINARY););
DBUG_RETURN(m_cond->cond_push(cond, table, (NDBTAB *)m_table));
=== modified file 'sql/ha_ndbcluster_cond.cc'
--- a/sql/ha_ndbcluster_cond.cc 2011-01-14 14:15:54 +0000
+++ b/sql/ha_ndbcluster_cond.cc 2011-01-17 13:29:52 +0000
@@ -972,7 +972,7 @@ ha_ndbcluster_cond::cond_push(const Item
if (ndb_cond == NULL)
{
my_errno= HA_ERR_OUT_OF_MEM;
- DBUG_RETURN(NULL);
+ DBUG_RETURN(cond);
}
if (m_cond_stack)
ndb_cond->next= m_cond_stack;
Attachment: [text/bzr-bundle] bzr/ole.john.aske@oracle.com-20110117132952-q6poszeqy1pbflwf.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.0 branch (ole.john.aske:4124) Bug#58791 | Ole John Aske | 17 Jan |