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

EXISTS to IN is not reflected in the optimizer trace

Details

    Description

      --- a/mysql-test/main/subselect_exists2in_costmat.test
      +++ b/mysql-test/main/subselect_exists2in_costmat.test
      @@ -65,19 +65,24 @@ set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materializ
       -- echo Q1.1m:
       -- echo MATERIALIZATION: there are too many rows in the outer query
       -- echo to be looked up in the inner table.
      -EXPLAIN
      +EXPLAIN EXTENDED
       SELECT Name FROM Country
       WHERE (EXISTS (select 1 from City where City.Population > 100000 and
       Code = Country) OR
              Name LIKE 'L%') AND
             surfacearea > 1000000;
       
      +
      +set optimizer_trace=1;
      +
       SELECT Name FROM Country
       WHERE (EXISTS (select 1 from City where City.Population > 100000 and
       Code = Country) OR
              Name LIKE 'L%') AND
             surfacearea > 1000000;
       
      +select * from information_schema.optimizer_trace;
      +
       drop database world;
       
       set optimizer_switch=@subselect_mat_cost;
      

      Attachments

        Issue Links

          Activity

            An example of how in-to-exists is traced:

                      {
                        "transformation": {
                          "select_id": 2,
                          "from": "IN (SELECT)",
                          "to": "materialization",
                          "sjm_scan_allowed": true,
                          "possible": true
                        }
                      },
            

            psergei Sergei Petrunia added a comment - An example of how in-to-exists is traced: { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } },

            Suggested way of tracing exists-to-in:

            {
              "transformation": {
                "select_id": N,
                "from": "EXISTS (SELECT)",
                "to": "IN (SELECT)"
              }
            }
            

            psergei Sergei Petrunia added a comment - Suggested way of tracing exists-to-in: { "transformation" : { "select_id" : N, "from" : "EXISTS (SELECT)" , "to" : "IN (SELECT)" } }

            Function doing the conversion: Item_exists_subselect::exists2in_processor

            psergei Sergei Petrunia added a comment - Function doing the conversion: Item_exists_subselect::exists2in_processor
            Johnston Rex Johnston added a comment - - edited

            above test case, world database....

            set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
             
            -- echo
            -- echo 1. Subquery in a disjunctive WHERE clause of the outer query.
            -- echo
             
            -- echo
            -- echo Q1.1m:
            -- echo MATERIALIZATION: there are too many rows in the outer query
            -- echo to be looked up in the inner table.
            EXPLAIN EXTENDED
            SELECT Name FROM Country
            WHERE ( EXISTS (select 1 from City where City.Population > 100000 and Country.Code = City.Country) 
            	        OR (Country.Name LIKE 'L%') )
            	AND surfacearea > 1000000;
             
            set optimizer_trace=1;
             
            reset query cache;
             
            SELECT Name FROM Country
            WHERE (EXISTS (select 1 from City where City.Population > 100000 and Country.Code = City.Country)
            			OR (Country.Name LIKE 'L%') )
            	AND surfacearea > 1000000;
             
            select trace from information_schema.optimizer_trace into @trace;
            --select @trace as out1;
            --select json_extract(@trace, '$.steps[*].join_optimization') as out2;
            select json_detailed(json_extract(@trace, '$.steps[*].join_optimization')) into @trace_join_optimization;
             
            select @trace_join_optimization;
            --select json_detailed(json_extract(@trace_join_optimization, '$**.transformation') );
            

            produces

            @trace_join_optimization
            [
                
                {
                    "select_id": 1,
                    "steps": 
                    [
                        
                        {
                            "transformation": 
                            {
                                "select_id": 2,
                                "from": "EXISTS (SELECT)",
                                "to": "IN (SELECT)",
                                "upper_not": false
                            }
                        },
                        
                        {
                            "transformation": 
                            {
                                "select_id": 2,
                                "from": "IN (SELECT)",
                                "to": "materialization",
                                "sjm_scan_allowed": true,
                                "possible": true
                            }
                        },
                        
                        {
                            "condition_processing": 
            

            Johnston Rex Johnston added a comment - - edited above test case, world database.... set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';   -- echo -- echo 1. Subquery in a disjunctive WHERE clause of the outer query. -- echo   -- echo -- echo Q1.1m: -- echo MATERIALIZATION: there are too many rows in the outer query -- echo to be looked up in the inner table. EXPLAIN EXTENDED SELECT Name FROM Country WHERE ( EXISTS (select 1 from City where City.Population > 100000 and Country.Code = City.Country) OR (Country.Name LIKE 'L%') ) AND surfacearea > 1000000;   set optimizer_trace=1;   reset query cache;   SELECT Name FROM Country WHERE (EXISTS (select 1 from City where City.Population > 100000 and Country.Code = City.Country) OR (Country.Name LIKE 'L%') ) AND surfacearea > 1000000;   select trace from information_schema.optimizer_trace into @trace; --select @trace as out1; --select json_extract(@trace, '$.steps[*].join_optimization') as out2; select json_detailed(json_extract(@trace, '$.steps[*].join_optimization')) into @trace_join_optimization;   select @trace_join_optimization; --select json_detailed(json_extract(@trace_join_optimization, '$**.transformation') ); produces @trace_join_optimization [ { "select_id": 1, "steps": [ { "transformation": { "select_id": 2, "from": "EXISTS (SELECT)", "to": "IN (SELECT)", "upper_not": false } }, { "transformation": { "select_id": 2, "from": "IN (SELECT)", "to": "materialization", "sjm_scan_allowed": true, "possible": true } }, { "condition_processing":

            The patch is in preview-11.0-preview tree

            psergei Sergei Petrunia added a comment - The patch is in preview-11.0-preview tree

            People

              psergei Sergei Petrunia
              sanja Oleksandr Byelkin
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.