Commit aef1982b authored by Venkata Sidagam's avatar Venkata Sidagam

Bug #12876932 - INCORRECT SELECT RESULT ON FEDERATED TABLE

Problem description:
Table 't' created with two colums having compound index on both the 
columns under innodb/myisam engine at remote machine. In the local 
machine same table is created undet the federated engine.
A select having where clause with along 'AND' operation gives wrong 
results on local machine.

Analysis: 
The given query at federated engine is wrongly transformed by 
federated::create_where_from_key() function and the same was sent to 
the remote machine. Hence the local machine is showing wrong results.

Given query "select c1 from t where c1 <= 2 and c2 = 1;"
Query transformed, after ha_federated::create_where_from_key() function is:
SELECT `c1`, `c2` FROM `t` WHERE  (`c1` IS NOT NULL ) AND 
( (`c1` >= 2)  AND  (`c2` <= 1) ) and the same sent to real_query().
In the above the '<=' and '=' conditions were transformed to '>=' and 
'<=' respectively.

ha_federated::create_where_from_key() function behaving as below:
The key_range is having both the start_key and end_key. The start_key 
is used to get "(`c1` IS NOT NULL )" part of the where clause, this 
transformation is correct. The end_key is used to get "( (`c1` >= 2) 
AND  (`c2` <= 1) )", which is wrong, here the given conditions('<=' and '=') 
are changed as wrong conditions('>=' and '<=').
The end_key is having {key = 0x39fa6d0 "", length = 10, keypart_map = 3, 
flag = HA_READ_AFTER_KEY}

The store_length is having value '5'. Based on store_length and length 
values the condition values is applied in HA_READ_AFTER_KEY switch case.
The switch case 'HA_READ_AFTER_KEY' is applicable to only the last part of 
the end_key and for previous parts it is going to 'HA_READ_KEY_OR_NEXT' case, 
here the '>=' is getting added as a condition instead of '<='.

Fix:
Updated the 'if' condition in 'HA_READ_AFTER_KEY' case to affect for all 
parts of the end_key. i.e 'i > 0' will used for end_key, Hence added it in 
the if condition.


mysql-test/suite/federated/federated.test:
  modified the federated.inc file location
mysql-test/suite/federated/federated_archive.test:
  modified the federated.inc file location
mysql-test/suite/federated/federated_bug_13118.test:
  modified the federated.inc file location
mysql-test/suite/federated/federated_bug_25714.test:
  modified the federated.inc file location
mysql-test/suite/federated/federated_bug_35333.test:
  modified the federated.inc file location
mysql-test/suite/federated/federated_debug.test:
  modified the federated.inc file location
mysql-test/suite/federated/federated_innodb.test:
  modified the federated.inc file location
mysql-test/suite/federated/federated_server.test:
  modified the federated.inc file location
mysql-test/suite/federated/federated_transactions.test:
  modified the federated.inc file location
mysql-test/suite/federated/include/federated.inc:
  moved the file from federated suite to federated/include folder
mysql-test/suite/federated/include/federated_cleanup.inc:
  moved the file from federated suite to federated/include folder
mysql-test/suite/federated/include/have_federated_db.inc:
  moved the file from federated suite to federated/include folder
storage/federated/ha_federated.cc:
  updated the 'if condition' in ha_federated::create_where_from_key() 
  function.
parent 13836600
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# should work with embedded server after mysqltest is fixed # should work with embedded server after mysqltest is fixed
--source include/not_embedded.inc --source include/not_embedded.inc
--source federated.inc --source suite/federated/include/federated.inc
connection default; connection default;
...@@ -1999,4 +1999,4 @@ connection slave; ...@@ -1999,4 +1999,4 @@ connection slave;
SET @@GLOBAL.CONCURRENT_INSERT= @OLD_SLAVE_CONCURRENT_INSERT; SET @@GLOBAL.CONCURRENT_INSERT= @OLD_SLAVE_CONCURRENT_INSERT;
connection default; connection default;
source federated_cleanup.inc; source suite/federated/include/federated_cleanup.inc;
source include/have_archive.inc; source include/have_archive.inc;
source federated.inc; source suite/federated/include/federated.inc;
connection slave; connection slave;
...@@ -54,5 +54,5 @@ connection slave; ...@@ -54,5 +54,5 @@ connection slave;
DROP TABLE federated.archive_table; DROP TABLE federated.archive_table;
source federated_cleanup.inc; source suite/federated/include/federated_cleanup.inc;
source federated.inc; source suite/federated/include/federated.inc;
connection slave; connection slave;
--disable_warnings --disable_warnings
...@@ -37,5 +37,5 @@ connection slave; ...@@ -37,5 +37,5 @@ connection slave;
DROP TABLE federated.bug_13118_table; DROP TABLE federated.bug_13118_table;
source federated_cleanup.inc; source suite/federated/include/federated_cleanup.inc;
...@@ -4,7 +4,7 @@ if (`select LENGTH("$MYSQL_BUG25714") = 0`) ...@@ -4,7 +4,7 @@ if (`select LENGTH("$MYSQL_BUG25714") = 0`)
skip Need bug25714 test program; skip Need bug25714 test program;
} }
source federated.inc; source suite/federated/include/federated.inc;
connection master; connection master;
# Disable concurrent inserts to avoid test failures when reading # Disable concurrent inserts to avoid test failures when reading
...@@ -59,4 +59,4 @@ SET @@GLOBAL.CONCURRENT_INSERT= @OLD_SLAVE_CONCURRENT_INSERT; ...@@ -59,4 +59,4 @@ SET @@GLOBAL.CONCURRENT_INSERT= @OLD_SLAVE_CONCURRENT_INSERT;
source federated_cleanup.inc; source suite/federated/include/federated_cleanup.inc;
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
--echo # to complete while still indicating a problem. This fix applies to any non-fatal system --echo # to complete while still indicating a problem. This fix applies to any non-fatal system
--echo # error that occurs during a query against I_S.TABLES.de --echo # error that occurs during a query against I_S.TABLES.de
--source federated.inc --source suite/federated/include/federated.inc
--disable_warnings --disable_warnings
CREATE DATABASE IF NOT EXISTS realdb; CREATE DATABASE IF NOT EXISTS realdb;
...@@ -71,4 +71,4 @@ DROP TABLE IF EXISTS federated.t0; ...@@ -71,4 +71,4 @@ DROP TABLE IF EXISTS federated.t0;
DROP DATABASE realdb; DROP DATABASE realdb;
--enable_warnings --enable_warnings
--source federated_cleanup.inc --source suite/federated/include/federated_cleanup.inc
--source include/have_debug.inc --source include/have_debug.inc
--source federated.inc --source suite/federated/include/federated.inc
--echo # --echo #
--echo # Bug#47525: MySQL crashed (Federated) --echo # Bug#47525: MySQL crashed (Federated)
...@@ -36,4 +36,4 @@ DROP TABLE t1; ...@@ -36,4 +36,4 @@ DROP TABLE t1;
connection default; connection default;
--echo # Federated cleanup --echo # Federated cleanup
source federated_cleanup.inc; source suite/federated/include/federated_cleanup.inc;
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# See Bug #40645 Test main.federated_innodb does not always clean up after itself # See Bug #40645 Test main.federated_innodb does not always clean up after itself
source include/have_innodb.inc; source include/have_innodb.inc;
source federated.inc; source suite/federated/include/federated.inc;
# #
# Bug#25513 Federated transaction failures # Bug#25513 Federated transaction failures
...@@ -36,4 +36,4 @@ connection slave; ...@@ -36,4 +36,4 @@ connection slave;
drop table federated.t1; drop table federated.t1;
source federated_cleanup.inc; source suite/federated/include/federated_cleanup.inc;
# WL #3031 This test tests the new servers table as well as # WL #3031 This test tests the new servers table as well as
# if federated can utilise the servers table # if federated can utilise the servers table
-- source federated.inc -- source suite/federated/include/federated.inc
connection slave; connection slave;
create database first_db; create database first_db;
...@@ -333,4 +333,4 @@ drop procedure p1; ...@@ -333,4 +333,4 @@ drop procedure p1;
drop server if exists s; drop server if exists s;
source federated_cleanup.inc; source suite/federated/include/federated_cleanup.inc;
source include/have_innodb.inc; source include/have_innodb.inc;
source federated.inc; source suite/federated/include/federated.inc;
connection slave; connection slave;
DROP TABLE IF EXISTS federated.t1; DROP TABLE IF EXISTS federated.t1;
...@@ -35,4 +35,4 @@ INSERT INTO federated.t1 (id, name) VALUES (6, 'fig'); ...@@ -35,4 +35,4 @@ INSERT INTO federated.t1 (id, name) VALUES (6, 'fig');
SELECT * FROM federated.t1; SELECT * FROM federated.t1;
DELETE FROM federated.t1; DELETE FROM federated.t1;
source federated_cleanup.inc; source suite/federated/include/federated_cleanup.inc;
--source include/not_embedded.inc --source include/not_embedded.inc
--source have_federated_db.inc --source suite/federated/include/have_federated_db.inc
connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,); connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,); connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# #
-- source include/have_partition.inc -- source include/have_partition.inc
-- source include/not_embedded.inc -- source include/not_embedded.inc
-- source suite/federated/have_federated_db.inc -- source suite/federated/include/have_federated_db.inc
--disable_warnings --disable_warnings
drop table if exists t1; drop table if exists t1;
......
...@@ -1364,7 +1364,7 @@ bool ha_federated::create_where_from_key(String *to, ...@@ -1364,7 +1364,7 @@ bool ha_federated::create_where_from_key(String *to,
break; break;
} }
DBUG_PRINT("info", ("federated HA_READ_AFTER_KEY %d", i)); DBUG_PRINT("info", ("federated HA_READ_AFTER_KEY %d", i));
if (store_length >= length) /* end key */ if ((store_length >= length) || (i > 0)) /* for all parts of end key*/
{ {
if (emit_key_part_name(&tmp, key_part)) if (emit_key_part_name(&tmp, key_part))
goto err; goto err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment