[MXS-957] Temporary table creation from another temporary table isn't detected Created: 2016-10-26  Updated: 2016-10-26  Resolved: 2016-10-26

Status: Closed
Project: MariaDB MaxScale
Component/s: readwritesplit
Affects Version/s: 2.0.1
Fix Version/s: 2.0.2

Type: Bug Priority: Critical
Reporter: markus makela Assignee: markus makela
Resolution: Fixed Votes: 0
Labels: None


 Description   

When the following SQL is executed through readwritesplit, the last statement fails because it is routed to a slave instead of the master.

CREATE OR REPLACE TABLE t1(`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY);
CREATE OR REPLACE TABLE t2(`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY);
CREATE TEMPORARY TABLE temp1(`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY);
INSERT INTO temp1 values (1), (2), (3);
INSERT INTO t1 values (1), (2), (3);
INSERT INTO t2 values (1), (2), (3);
CREATE TEMPORARY TABLE temp2 SELECT DISTINCT p.id FROM temp1 p JOIN t1 t ON (t.id = p.id) LEFT JOIN t2 ON (t.id = t2.id) WHERE p.id IS NOT NULL AND @@server_id IS NOT NULL;
SELECT * FROM temp2;

This is caused by the following code in readwritesplit.c which replaces the query type instead of amending to the value.

        /**
         * Check if the query has anything to do with temporary tables.
         */
        if (rses->have_tmp_tables &&
            (packet_type == MYSQL_COM_QUERY || packet_type == MYSQL_COM_DROP_DB))
        {
            check_drop_tmp_table(rses, querybuf, qtype);
            if (packet_type == MYSQL_COM_QUERY)
            {
                qtype = is_read_tmp_table(rses, querybuf, qtype);
            }
        }
        check_create_tmp_table(rses, querybuf, qtype);



 Comments   
Comment by markus makela [ 2016-10-26 ]

Temporary table reads in CREATE TABLE statements are now properly detected.

Generated at Thu Feb 08 04:03:10 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.