Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-6704

Wrong result (extra rows) on 2nd execution of PS with exists_to_in, MERGE view

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Critical
    • Resolution: Unresolved
    • 10.0.13, 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL)
    • 10.5, 10.6
    • None
    • 10.0.20, 10.0.24

    Description

      CREATE TABLE t1 (a VARCHAR(3)) ENGINE=MyISAM;
      INSERT INTO t1 VALUES ('foo'),('bar');
       
      CREATE TABLE t2 (i INT, b VARCHAR(3)) ENGINE=MyISAM;
      CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
      INSERT INTO t2 VALUES (4,'foo'),(5,'baz');
       
      PREPARE stmt FROM "SELECT * FROM t1 WHERE NOT EXISTS ( SELECT i FROM v2 WHERE b = a )";
      EXECUTE stmt;
      EXECUTE stmt;

      Actual result:

      EXECUTE stmt;
      a
      bar
      EXECUTE stmt;
      a
      foo
      bar

      Expected result:

      EXECUTE stmt;
      a
      bar
      EXECUTE stmt;
      a
      bar

      revision-id: knielsen@knielsen-hq.org-20140902120701-txesdmkczel84qgf
      revno: 4369
      branch-nick: 10.0

      Attachments

        Issue Links

          Activity

            elenst Elena Stepanova created issue -
            sanja Oleksandr Byelkin made changes -
            Field Original Value New Value
            Status Open [ 1 ] In Progress [ 3 ]
            sanja Oleksandr Byelkin made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            sanja Oleksandr Byelkin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            sanja Oleksandr Byelkin added a comment - - edited

            Difference between 2 executions found:
            WHERE:(t1 final_pushdown_cond) 0x7fa04c1599c8 (not(((`test`.`t1`.`a` is not null) and <in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`b` from `test`.`v2` where (`test`.`t2`.`b` is not null))))))

            WHERE:(t1 final_pushdown_cond) 0x7fa04c1599c8 (not(((`test`.`t1`.`a` is not null) and <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in (select `test`.`t2`.`i` from `test`.`t2` where (`test`.`t2`.`b` is not null))))))

            sanja Oleksandr Byelkin added a comment - - edited Difference between 2 executions found: WHERE:(t1 final_pushdown_cond) 0x7fa04c1599c8 (not(((`test`.`t1`.`a` is not null) and <in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`b` from `test`.`v2` where (`test`.`t2`.`b` is not null)))))) WHERE:(t1 final_pushdown_cond) 0x7fa04c1599c8 (not(((`test`.`t1`.`a` is not null) and <in_optimizer>(`test`.`t1`.`a` ,`test`.`t1`.`a` in (select `test`.`t2`.`i` from `test`.`t2` where (`test`.`t2`.`b` is not null))))))

            Above is result about taking materialization strategy for IN subquery which was done later then printed first line but kept till next execution.

            sanja Oleksandr Byelkin added a comment - Above is result about taking materialization strategy for IN subquery which was done later then printed first line but kept till next execution.

            subselect_uniquesubquery_engine::exec() on the second execution looks for incorrect key:

            gdb) p (*key)@9
            $3 = "\000\000\000\000\000\000\000\000"

            against first execution key:

            (gdb) p (*key)@9
            $2 = "\000\003\000foo\000\000"

            sanja Oleksandr Byelkin added a comment - subselect_uniquesubquery_engine::exec() on the second execution looks for incorrect key: gdb) p (*key)@9 $3 = "\000\000\000\000\000\000\000\000" against first execution key: (gdb) p (*key)@9 $2 = "\000\003\000foo\000\000"

            Above happened because it trying to store in Field_long 'i' !!!

            sanja Oleksandr Byelkin added a comment - Above happened because it trying to store in Field_long 'i' !!!

            subselect_hash_sj_engine::make_unique_engine() creates subselect_uniquesubquery_engine for every execution, so probably works incorrectly on the second one picking up wrong field.

            sanja Oleksandr Byelkin added a comment - subselect_hash_sj_engine::make_unique_engine() creates subselect_uniquesubquery_engine for every execution, so probably works incorrectly on the second one picking up wrong field.

            tmp_key->key_part changed

            sanja Oleksandr Byelkin added a comment - tmp_key->key_part changed
            sanja Oleksandr Byelkin made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Workflow MariaDB v2 [ 53736 ] MariaDB v3 [ 66560 ]
            serg Sergei Golubchik made changes -
            Sprint 10.0.20 [ 5 ]
            serg Sergei Golubchik made changes -
            Sprint 10.0.20 [ 5 ] 10.0.20, 10.1.6-1 [ 5, 6 ]
            serg Sergei Golubchik made changes -
            Rank Ranked higher
            serg Sergei Golubchik made changes -
            Sprint 10.0.20, 10.1.6-1 [ 5, 6 ] 10.0.20 [ 5 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Sprint 10.0.20 [ 5 ] 10.0.20, 10.0.24-0 [ 5, 35 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Rank Ranked higher
            sanja Oleksandr Byelkin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]

            First call
            T@6 : | | | | | | | | | | | | | | | >subselect_uniquesubquery_engine::exec
            T@6 : | | | | | | | | | | | | | | | | >subselect_uniquesubquery_engine::copy_ref_key
            T@6 : | | | | | | | | | | | | | | | | | >save_field_in_field
            T@6 : | | | | | | | | | | | | | | | | | | XXX: a.t1(./test/t1) -> b.<subquery2>(/home/sanja/maria/git/server/mysql-test/var/tmp/mysqld.1/#sql_739c_1)
            T@6 : | | | | | | | | | | | | | | | | | <save_field_in_field
            T@6 : | | | | | | | | | | | | | | | | <subselect_uniquesubquery_engine::copy_ref_key
            T@6 : | | | | | | | | | | | | | | | | >ha_index_init
            T@6 : | | | | | | | | | | | | | | | | <ha_index_init
            T@6 : | | | | | | | | | | | | | | | | >handler::ha_index_read_map
            T@6 : | | | | | | | | | | | | | | | | | XXX: Memory: 0x7f60d1111fa8 Bytes: (7)
            00 03 00 66 6F 6F 00

            Second call:

            T@6 : | | | | | | | | | | | | | | | >subselect_uniquesubquery_engine::exec
            T@6 : | | | | | | | | | | | | | | | | >subselect_uniquesubquery_engine::copy_ref_key
            T@6 : | | | | | | | | | | | | | | | | | >save_field_in_field
            T@6 : | | | | | | | | | | | | | | | | | | XXX: a.t1(./test/t1) -> i.<subquery2>(/home/sanja/maria/git/server/mysql-test/var/tmp/mysqld.1/#sql_739c_1)
            T@6 : | | | | | | | | | | | | | | | | | <save_field_in_field
            T@6 : | | | | | | | | | | | | | | | | <subselect_uniquesubquery_engine::copy_ref_key
            T@6 : | | | | | | | | | | | | | | | | >ha_index_init
            T@6 : | | | | | | | | | | | | | | | | <ha_index_init
            T@6 : | | | | | | | | | | | | | | | | >handler::ha_index_read_map
            T@6 : | | | | | | | | | | | | | | | | | XXX: Memory: 0x7f60d112a008 Bytes: (5)
            00 00 00 00 00

            sanja Oleksandr Byelkin added a comment - First call T@6 : | | | | | | | | | | | | | | | >subselect_uniquesubquery_engine::exec T@6 : | | | | | | | | | | | | | | | | >subselect_uniquesubquery_engine::copy_ref_key T@6 : | | | | | | | | | | | | | | | | | >save_field_in_field T@6 : | | | | | | | | | | | | | | | | | | XXX: a.t1(./test/t1) -> b.<subquery2>(/home/sanja/maria/git/server/mysql-test/var/tmp/mysqld.1/#sql_739c_1) T@6 : | | | | | | | | | | | | | | | | | <save_field_in_field T@6 : | | | | | | | | | | | | | | | | <subselect_uniquesubquery_engine::copy_ref_key T@6 : | | | | | | | | | | | | | | | | >ha_index_init T@6 : | | | | | | | | | | | | | | | | <ha_index_init T@6 : | | | | | | | | | | | | | | | | >handler::ha_index_read_map T@6 : | | | | | | | | | | | | | | | | | XXX: Memory: 0x7f60d1111fa8 Bytes: (7) 00 03 00 66 6F 6F 00 Second call: T@6 : | | | | | | | | | | | | | | | >subselect_uniquesubquery_engine::exec T@6 : | | | | | | | | | | | | | | | | >subselect_uniquesubquery_engine::copy_ref_key T@6 : | | | | | | | | | | | | | | | | | >save_field_in_field T@6 : | | | | | | | | | | | | | | | | | | XXX: a.t1(./test/t1) -> i.<subquery2>(/home/sanja/maria/git/server/mysql-test/var/tmp/mysqld.1/#sql_739c_1) T@6 : | | | | | | | | | | | | | | | | | <save_field_in_field T@6 : | | | | | | | | | | | | | | | | <subselect_uniquesubquery_engine::copy_ref_key T@6 : | | | | | | | | | | | | | | | | >ha_index_init T@6 : | | | | | | | | | | | | | | | | <ha_index_init T@6 : | | | | | | | | | | | | | | | | >handler::ha_index_read_map T@6 : | | | | | | | | | | | | | | | | | XXX: Memory: 0x7f60d112a008 Bytes: (5) 00 00 00 00 00

            changing the DESTINATION field can explain a problem...

            sanja Oleksandr Byelkin added a comment - changing the DESTINATION field can explain a problem...
            sanja Oleksandr Byelkin added a comment - - edited

            Second time used other engine, so probably passing the same JOIN_TAB address to it is just a coincidence or (using wrong JOIN (small probability, because it should be freed)).

            sanja Oleksandr Byelkin added a comment - - edited Second time used other engine, so probably passing the same JOIN_TAB address to it is just a coincidence or (using wrong JOIN (small probability, because it should be freed)).
            sanja Oleksandr Byelkin added a comment - - edited

            The problem is that Item_in_subselect::setup_mat_engine() uses select_engine->join->fields_list which on the second execution chaged due to transformation rollback!!!

            sanja Oleksandr Byelkin added a comment - - edited The problem is that Item_in_subselect::setup_mat_engine() uses select_engine->join->fields_list which on the second execution chaged due to transformation rollback!!!
            sanja Oleksandr Byelkin made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            sanja Oleksandr Byelkin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]

            revision-id: 016f44b15455d2ca0018902cdc78d1cb29a14423 (mariadb-10.0.23-30-g016f44b)
            parent(s): 089b65fd5e8ecd1971cf4c6c372e20575ff4ca9e
            committer: Oleksandr Byelkin
            timestamp: 2016-02-14 16:52:56 +0100
            message:

            MDEV-6704: Wrong result (extra rows) on 2nd execution of PS with exists_to_in, MERGE view

            The problem was that after first execution permanent exists-to-in transformation became broken back by rolling back temporary changes of view resolving.

            Added method to rewrite temporary changes.

            —

            sanja Oleksandr Byelkin added a comment - revision-id: 016f44b15455d2ca0018902cdc78d1cb29a14423 (mariadb-10.0.23-30-g016f44b) parent(s): 089b65fd5e8ecd1971cf4c6c372e20575ff4ca9e committer: Oleksandr Byelkin timestamp: 2016-02-14 16:52:56 +0100 message: MDEV-6704 : Wrong result (extra rows) on 2nd execution of PS with exists_to_in, MERGE view The problem was that after first execution permanent exists-to-in transformation became broken back by rolling back temporary changes of view resolving. Added method to rewrite temporary changes. —
            sanja Oleksandr Byelkin made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            psergei Sergei Petrunia made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergei Petrunia [ psergey ]
            psergei Sergei Petrunia made changes -
            Status Stalled [ 10000 ] In Review [ 10002 ]

            Attempted to do a review pass, discussed with sanja. Current approach works but in my opinion change_item_tree() is evil and should not be extended.
            I'd like to come up with some other solution. I need to think about this.

            psergei Sergei Petrunia added a comment - Attempted to do a review pass, discussed with sanja . Current approach works but in my opinion change_item_tree() is evil and should not be extended. I'd like to come up with some other solution. I need to think about this.
            elenst Elena Stepanova made changes -
            Component/s Optimizer [ 10200 ]
            Component/s Prepared Statements [ 10804 ]
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.0 [ 16000 ]
            Affects Version/s 10.1 [ 16100 ]
            Affects Version/s 10.2 [ 14601 ]
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s 10.4 [ 22408 ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.1 [ 16100 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 66560 ] MariaDB v4 [ 143717 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 10.2 [ 14601 ]
            alice Alice Sherepa made changes -
            Affects Version/s 10.5 [ 23123 ]
            Affects Version/s 10.6 [ 24028 ]
            Affects Version/s 10.7 [ 24805 ]
            Affects Version/s 10.8 [ 26121 ]
            Affects Version/s 10.9 [ 26905 ]
            Affects Version/s 10.10 [ 27530 ]
            alice Alice Sherepa made changes -
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            serg Sergei Golubchik made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.7 [ 24805 ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.3 [ 22126 ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.8 [ 26121 ]
            igor Igor Babaev (Inactive) made changes -
            Assignee Sergei Petrunia [ psergey ] Igor Babaev [ igor ]
            igor Igor Babaev (Inactive) added a comment - - edited

            Just reassigned the bug to myself.

            igor Igor Babaev (Inactive) added a comment - - edited Just reassigned the bug to myself.
            igor Igor Babaev (Inactive) made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.9 [ 26905 ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.4 [ 22408 ]
            Johnston Rex Johnston made changes -
            Assignee Igor Babaev [ igor ] Rex Johnston [ JIRAUSER52533 ]

            People

              Johnston Rex Johnston
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.