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

spider returns parsing failure on valid left join select by translating the on expression to ()

Details

    Description

      This testcase works until 10.5.23 normal.

      With 10.5.24 the select trigger

      ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') where 1' at line 1
      

      Testcase to reproduce:

      docker run -d --name acd --env MARIADB_ROOT_PASSWORD=Maria2024!  mariadb:10.5.24
       
       
      docker exec -it acd bash
      apt update
      apt install mariadb-plugin-spider
       
      mysql -uroot -pMaria2024!
       
      INSTALL SONAME "ha_spider";
       
      create database archive;
      use archive;
       
       
      DROP TABLE if EXISTS `t1` ;
       
      CREATE TABLE `t1` (       `DOC_ID` INT(10) UNSIGNED NOT NULL,       `DOC_NOM` VARCHAR(255) NOT NULL ,       PRIMARY KEY (`DOC_ID`) USING BTREE ) ENGINE=MYISAM ;
       
      DROP TABLE if EXISTS `t2` ;
       
      CREATE TABLE `t2` (       `DAA_ID` INT(10) UNSIGNED NOT NULL,       `DOC_ID` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM ;
       
      SET spider_same_server_link= on;
       
      create server s foreign data wrapper mysql options (host "127.0.0.1", database "archive", user "root", password "Maria2016!", PORT 3306 );
       
      DROP TABLE if EXISTS `t2_spider` ;
       
      CREATE TABLE `t2_spider` (       `DAA_ID` INT(10) UNSIGNED NOT NULL,       `DOC_ID` INT(10) UNSIGNED NOT NULL,       PRIMARY KEY (`DAA_ID`) USING BTREE ) COMMENT='wrapper "mysql",srv "s",table "t2"' ENGINE=SPIDER ;
       
       
       
      DROP TABLE if EXISTS `t1_spider` ;
       
       
       CREATE TABLE `t1_spider` (       `DOC_ID` INT(10) UNSIGNED NOT NULL,       `DOC_NOM` VARCHAR(255) NOT NULL ,       PRIMARY KEY (`DOC_ID`) USING BTREE ) COMMENT='wrapper "mysql",srv "s", table "t1"' ENGINE=SPIDER;
       
       
       
      INSERT INTO t1_spider VALUES(1,'oooo');
       
      INSERT INTO t2_spider VALUES(1,1);
       
       
       
      SELECT t2_spider.DAA_ID,t1_spider.DOC_ID FRoM t2_spider LEFT join  t1_spider ON (t2_spider.DOC_ID = t1_spider.DOC_ID)  WHERE t2_spider.DAA_ID = 1;
      

      Attachments

        Issue Links

          Activity

            ycp Yuchen Pei added a comment - - edited

            While I'm working on a fix, may I suggest a potential workaround of disabling the spider group by handler.

            For mariadb of version < 10.10, it can be done by set spider_use_handler= 1;

            For mariadb of version >= 10.10 that contains MDEV-32238, it can be done by set spider_disable_group_by_handler= 1;

            Note that with the workaround the testcase may still fail due to inconsistent indexes (t2 has no primary keys specified but t2_spider has), which is expected

            ycp Yuchen Pei added a comment - - edited While I'm working on a fix, may I suggest a potential workaround of disabling the spider group by handler. For mariadb of version < 10.10, it can be done by set spider_use_handler= 1; For mariadb of version >= 10.10 that contains MDEV-32238 , it can be done by set spider_disable_group_by_handler= 1; Note that with the workaround the testcase may still fail due to inconsistent indexes (t2 has no primary keys specified but t2_spider has), which is expected
            ycp Yuchen Pei added a comment - - edited

            The reason it fails is because during query construction, the spider group by handler cannot handle multiple equalities correctly. It translates {{Item_equal}}s to empty strings.

            I created a patch to translate Item_equal into an AND-list of equalities that works on the testcase and does not seem to introduce regressions:

            2562cd38a18 upstream/bb-10.5-mdev-33679-print-item-equal MDEV-33679 [poc] Construct queries for Item_equal in spider group by handler
            

            However, this needs to be tested for when there are more than two items in an Item_equal. A trivial case does not seem to trigger that:

            create table t1 (a INT, b INT, c INT);
            create table t2 (a INT, b INT, c INT) engine=SPIDER COMMENT='wrapper "mysql",srv "srv",table "t1"';
            insert into t2 values (1, 2, 3), (5, 4, 3), (3, 3, 3);
            select * from t2 where a = b and b = c;
            

            I also note that if we remove the mismatching index in the original case as mentioned in the previous comment, we also do not end up having to handle any {{Item_equal}}s.

            ycp Yuchen Pei added a comment - - edited The reason it fails is because during query construction, the spider group by handler cannot handle multiple equalities correctly. It translates {{Item_equal}}s to empty strings. I created a patch to translate Item_equal into an AND-list of equalities that works on the testcase and does not seem to introduce regressions: 2562cd38a18 upstream/bb-10.5-mdev-33679-print-item-equal MDEV-33679 [poc] Construct queries for Item_equal in spider group by handler However, this needs to be tested for when there are more than two items in an Item_equal . A trivial case does not seem to trigger that: create table t1 (a INT , b INT , c INT ); create table t2 (a INT , b INT , c INT ) engine=SPIDER COMMENT= 'wrapper "mysql",srv "srv",table "t1"' ; insert into t2 values (1, 2, 3), (5, 4, 3), (3, 3, 3); select * from t2 where a = b and b = c; I also note that if we remove the mismatching index in the original case as mentioned in the previous comment, we also do not end up having to handle any {{Item_equal}}s.
            ycp Yuchen Pei added a comment -

            Hi holyfoot, ptal thanks

            upstream/bb-10.4-mdev-33679 855e05c25c943c6b05e4232b483b928f0fca2048
            MDEV-33679 Spider group by handler: skip on multiple equalities
             
            The spider group by handler is created in
            JOIN::make_aggr_tables_info(), by which time calls to
            substitute_for_best_equal_field() should have already removed all the
            multiple equalities (i.e. Item_equal, with MULT_EQUAL_FUNC func_type).
            Therefore, if there is still such items, it is deemed as an optimizer
            bug and should be skipped.
            

            ycp Yuchen Pei added a comment - Hi holyfoot , ptal thanks upstream/bb-10.4-mdev-33679 855e05c25c943c6b05e4232b483b928f0fca2048 MDEV-33679 Spider group by handler: skip on multiple equalities   The spider group by handler is created in JOIN::make_aggr_tables_info(), by which time calls to substitute_for_best_equal_field() should have already removed all the multiple equalities (i.e. Item_equal, with MULT_EQUAL_FUNC func_type). Therefore, if there is still such items, it is deemed as an optimizer bug and should be skipped.

            ok to push.

            holyfoot Alexey Botchkov added a comment - ok to push.
            ycp Yuchen Pei added a comment -

            thanks for the review, pushed 860c1ca9ad90654f5064796e0989f29dd3ac1b59 to 10.4

            ycp Yuchen Pei added a comment - thanks for the review, pushed 860c1ca9ad90654f5064796e0989f29dd3ac1b59 to 10.4

            People

              ycp Yuchen Pei
              Richard Richard Stracke
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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