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

No records produced in information_schema query, depending on projection

Details

    Description

      Create a table with a check constraint:

      create table t (i int, constraint a check (i > 0));
      

      Now consider this query, which should produce the above check constraint:

      select 
        tc.TABLE_SCHEMA, 
        tc.TABLE_NAME, 
        cc.CONSTRAINT_NAME, 
        cc.CHECK_CLAUSE
      from information_schema.TABLE_CONSTRAINTS tc
        join information_schema.CHECK_CONSTRAINTS cc
          using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME)
      ;
      

      It does not produce any results.

      Add two columns to the projection and ta-dah, we get the desired output:

      select 
        tc.TABLE_SCHEMA, 
        tc.TABLE_NAME, 
        cc.CONSTRAINT_NAME, 
        cc.CHECK_CLAUSE,
        tc.CONSTRAINT_CATALOG, 
        tc.CONSTRAINT_SCHEMA
      from information_schema.TABLE_CONSTRAINTS tc
        join information_schema.CHECK_CONSTRAINTS cc
          using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME)
      ;
      

      Attachments

        Issue Links

          Activity

            lukas.eder Lukas Eder created issue -
            lukas.eder Lukas Eder made changes -
            Field Original Value New Value
            Attachment screenshot-1.png [ 49576 ]
            lukas.eder Lukas Eder made changes -
            Attachment screenshot-2.png [ 49577 ]

            Thanks for the report and test case. Reproducible as described on 10.3-10.5. Not reproducible on 10.2.

            elenst Elena Stepanova added a comment - Thanks for the report and test case. Reproducible as described on 10.3-10.5. Not reproducible on 10.2.
            elenst Elena Stepanova made changes -
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s 10.4 [ 22408 ]
            Assignee Oleksandr Byelkin [ sanja ]
            elenst Elena Stepanova made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            sanja Oleksandr Byelkin made changes -
            Status Confirmed [ 10101 ] In Progress [ 3 ]

            Something wrong with USING, but it is not just conversion:

            create table t (i int, constraint a check (i > 0));
            select 
            tc.TABLE_SCHEMA, 
            tc.TABLE_NAME, 
            cc.CONSTRAINT_NAME, 
            cc.CHECK_CLAUSE
            from information_schema.TABLE_CONSTRAINTS tc
            join information_schema.CHECK_CONSTRAINTS cc
            using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME)
            ;
            TABLE_SCHEMA	TABLE_NAME	CONSTRAINT_NAME	CHECK_CLAUSE
            explain extended
            select 
            tc.TABLE_SCHEMA, 
            tc.TABLE_NAME, 
            cc.CONSTRAINT_NAME, 
            cc.CHECK_CLAUSE
            from information_schema.TABLE_CONSTRAINTS tc
            join information_schema.CHECK_CONSTRAINTS cc
            using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME)
            ;
            id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
            1	SIMPLE	tc	ALL	NULL	NULL	NULL	NULL	NULL	NULL	Open_full_table; Scanned all databases
            1	SIMPLE	cc	ALL	NULL	NULL	NULL	NULL	NULL	NULL	Using where; Open_full_table; Scanned all databases; Using join buffer (flat, BNL join)
            Warnings:
            Note	1003	select `tc`.`TABLE_SCHEMA` AS `TABLE_SCHEMA`,`tc`.`TABLE_NAME` AS `TABLE_NAME`,`cc`.`CONSTRAINT_NAME` AS `CONSTRAINT_NAME`,`cc`.`CHECK_CLAUSE` AS `CHECK_CLAUSE` from `information_schema`.`TABLE_CONSTRAINTS` `tc` join `information_schema`.`CHECK_CONSTRAINTS` `cc` where `cc`.`CONSTRAINT_CATALOG` = `tc`.`CONSTRAINT_CATALOG` and `cc`.`CONSTRAINT_SCHEMA` = `tc`.`CONSTRAINT_SCHEMA` and `cc`.`CONSTRAINT_NAME` = `tc`.`CONSTRAINT_NAME` and `cc`.`TABLE_NAME` = `tc`.`TABLE_NAME`
            select `tc`.`TABLE_SCHEMA` AS `TABLE_SCHEMA`,`tc`.`TABLE_NAME` AS `TABLE_NAME`,`cc`.`CONSTRAINT_NAME` AS `CONSTRAINT_NAME`,`cc`.`CHECK_CLAUSE` AS `CHECK_CLAUSE` from `information_schema`.`TABLE_CONSTRAINTS` `tc` join `information_schema`.`CHECK_CONSTRAINTS` `cc` where `cc`.`CONSTRAINT_CATALOG` = `tc`.`CONSTRAINT_CATALOG` and `cc`.`CONSTRAINT_SCHEMA` = `tc`.`CONSTRAINT_SCHEMA` and `cc`.`CONSTRAINT_NAME` = `tc`.`CONSTRAINT_NAME` and `cc`.`TABLE_NAME` = `tc`.`TABLE_NAME`
            ;
            TABLE_SCHEMA	TABLE_NAME	CONSTRAINT_NAME	CHECK_CLAUSE
            test	t	a	`i` > 0
            select 
            tc.TABLE_SCHEMA, 
            tc.TABLE_NAME, 
            cc.CONSTRAINT_NAME, 
            cc.CHECK_CLAUSE
            from information_schema.TABLE_CONSTRAINTS tc, information_schema.CHECK_CONSTRAINTS cc
            where cc.CONSTRAINT_CATALOG=tc.CONSTRAINT_CATALOG and cc.CONSTRAINT_SCHEMA=
            tc.CONSTRAINT_SCHEMA and cc.TABLE_NAME = tc.TABLE_NAME and
            cc.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
            ;
            TABLE_SCHEMA	TABLE_NAME	CONSTRAINT_NAME	CHECK_CLAUSE
            test	t	a	`i` > 0
            

            sanja Oleksandr Byelkin added a comment - Something wrong with USING, but it is not just conversion: create table t (i int, constraint a check (i > 0)); select tc.TABLE_SCHEMA, tc.TABLE_NAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE from information_schema.TABLE_CONSTRAINTS tc join information_schema.CHECK_CONSTRAINTS cc using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME) ; TABLE_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE explain extended select tc.TABLE_SCHEMA, tc.TABLE_NAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE from information_schema.TABLE_CONSTRAINTS tc join information_schema.CHECK_CONSTRAINTS cc using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME) ; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE tc ALL NULL NULL NULL NULL NULL NULL Open_full_table; Scanned all databases 1 SIMPLE cc ALL NULL NULL NULL NULL NULL NULL Using where; Open_full_table; Scanned all databases; Using join buffer (flat, BNL join) Warnings: Note 1003 select `tc`.`TABLE_SCHEMA` AS `TABLE_SCHEMA`,`tc`.`TABLE_NAME` AS `TABLE_NAME`,`cc`.`CONSTRAINT_NAME` AS `CONSTRAINT_NAME`,`cc`.`CHECK_CLAUSE` AS `CHECK_CLAUSE` from `information_schema`.`TABLE_CONSTRAINTS` `tc` join `information_schema`.`CHECK_CONSTRAINTS` `cc` where `cc`.`CONSTRAINT_CATALOG` = `tc`.`CONSTRAINT_CATALOG` and `cc`.`CONSTRAINT_SCHEMA` = `tc`.`CONSTRAINT_SCHEMA` and `cc`.`CONSTRAINT_NAME` = `tc`.`CONSTRAINT_NAME` and `cc`.`TABLE_NAME` = `tc`.`TABLE_NAME` select `tc`.`TABLE_SCHEMA` AS `TABLE_SCHEMA`,`tc`.`TABLE_NAME` AS `TABLE_NAME`,`cc`.`CONSTRAINT_NAME` AS `CONSTRAINT_NAME`,`cc`.`CHECK_CLAUSE` AS `CHECK_CLAUSE` from `information_schema`.`TABLE_CONSTRAINTS` `tc` join `information_schema`.`CHECK_CONSTRAINTS` `cc` where `cc`.`CONSTRAINT_CATALOG` = `tc`.`CONSTRAINT_CATALOG` and `cc`.`CONSTRAINT_SCHEMA` = `tc`.`CONSTRAINT_SCHEMA` and `cc`.`CONSTRAINT_NAME` = `tc`.`CONSTRAINT_NAME` and `cc`.`TABLE_NAME` = `tc`.`TABLE_NAME` ; TABLE_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE test t a `i` > 0 select tc.TABLE_SCHEMA, tc.TABLE_NAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE from information_schema.TABLE_CONSTRAINTS tc, information_schema.CHECK_CONSTRAINTS cc where cc.CONSTRAINT_CATALOG=tc.CONSTRAINT_CATALOG and cc.CONSTRAINT_SCHEMA= tc.CONSTRAINT_SCHEMA and cc.TABLE_NAME = tc.TABLE_NAME and cc.CONSTRAINT_NAME = tc.CONSTRAINT_NAME ; TABLE_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE test t a `i` > 0

            in JOIN_TAB::calc_used_field_length I see very strange field referecces with 0 pack_length inherited from Field_null...

            sanja Oleksandr Byelkin added a comment - in JOIN_TAB::calc_used_field_length I see very strange field referecces with 0 pack_length inherited from Field_null...

            create_schema_table() creates Item_empty_stringwith maximum length 0 and following code creates Field_null for the Item

            Field *Item::create_field_for_schema(THD *thd, TABLE *table)
            {
              if (field_type() == MYSQL_TYPE_VARCHAR)
              {
                Field *field;
                if (max_length > MAX_FIELD_VARCHARLENGTH)
                  field= new (thd->mem_root) Field_blob(max_length, maybe_null, &name,
                                                        collation.collation);
                else if (max_length > 0)
                  field= new (thd->mem_root) Field_varstring(max_length, maybe_null, &name,
                                                             table->s,
                                                             collation.collation);
                else
                  field= new Field_null((uchar*) 0, 0, Field::NONE, &name,
                                        collation.collation);
                if (field)
                  field->init(table);
                return field;
              }
              return tmp_table_field_from_field_type(table);
            }
            

            sanja Oleksandr Byelkin added a comment - create_schema_table() creates Item_empty_stringwith maximum length 0 and following code creates Field_null for the Item Field *Item::create_field_for_schema(THD *thd, TABLE *table) { if (field_type() == MYSQL_TYPE_VARCHAR) { Field *field; if (max_length > MAX_FIELD_VARCHARLENGTH) field= new (thd->mem_root) Field_blob(max_length, maybe_null, &name, collation.collation); else if (max_length > 0) field= new (thd->mem_root) Field_varstring(max_length, maybe_null, &name, table->s, collation.collation); else field= new Field_null((uchar*) 0, 0, Field::NONE, &name, collation.collation); if (field) field->init(table); return field; } return tmp_table_field_from_field_type(table); }

            It looks like the problem caused by e2664ee8362a94335df06edfc86936ff263d6dc0

            sanja Oleksandr Byelkin added a comment - It looks like the problem caused by e2664ee8362a94335df06edfc86936ff263d6dc0

            mark_all_fields_used_in_query() take into acount all Items, but it do not take into account USING fields which have no items yet

            sanja Oleksandr Byelkin added a comment - mark_all_fields_used_in_query() take into acount all Items, but it do not take into account USING fields which have no items yet

            Check natural join, probably we have probem with it

            sanja Oleksandr Byelkin added a comment - Check natural join, probably we have probem with it
            sanja Oleksandr Byelkin added a comment - - edited

            probably we have to have to allow matching with other table fields names in case of natural join

            sanja Oleksandr Byelkin added a comment - - edited probably we have to have to allow matching with other table fields names in case of natural join

            gin/bb-10.3-MDEV-21201)
            Author: Oleksandr Byelkin <sanja@mariadb.com>
            Date: Wed Jul 8 16:26:34 2020 +0200

            MDEV-21201 No records produced in information_schema query, depending on projection

            In case of USING check also join field list to mark fields as used.

            In case of NATURAL JOIN mark all field (one table can not be opened
            in any case so optimisation does not worth it).

            IMHO table should be checked for used fields and filled after prepare,
            when we will fave whole info about used fields but it is too big change
            for a bugfix.

            sanja Oleksandr Byelkin added a comment - gin/bb-10.3- MDEV-21201 ) Author: Oleksandr Byelkin <sanja@mariadb.com> Date: Wed Jul 8 16:26:34 2020 +0200 MDEV-21201 No records produced in information_schema query, depending on projection In case of USING check also join field list to mark fields as used. In case of NATURAL JOIN mark all field (one table can not be opened in any case so optimisation does not worth it). IMHO table should be checked for used fields and filled after prepare, when we will fave whole info about used fields but it is too big change for a bugfix.
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergei Golubchik [ serg ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            for now, please, just add something like

              if (natural join or union)
                birtmap_set_all(&bitmap);
            

            that is, disable the MDEV-14275 optimization in this case.
            I already have a fix that does it correctly in all applicable cases, I hope it can be pushed soon.

            serg Sergei Golubchik added a comment - for now, please, just add something like if (natural join or union ) birtmap_set_all(&bitmap); that is, disable the MDEV-14275 optimization in this case. I already have a fix that does it correctly in all applicable cases, I hope it can be pushed soon.
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Oleksandr Byelkin [ sanja ]
            Status In Review [ 10002 ] Stalled [ 10000 ]

            Temporary patch (not so efficient) pushed to 10.3. Proper fix will go later (next release).

            sanja Oleksandr Byelkin added a comment - Temporary patch (not so efficient) pushed to 10.3. Proper fix will go later (next release).
            sanja Oleksandr Byelkin made changes -
            Fix Version/s 10.3.24 [ 24306 ]
            Fix Version/s 10.4.14 [ 24305 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            sanja Oleksandr Byelkin made changes -
            Fix Version/s 10.5.5 [ 24423 ]
            varun Varun Gupta (Inactive) made changes -
            alice Alice Sherepa made changes -
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 101557 ] MariaDB v4 [ 157039 ]
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 155253

            People

              sanja Oleksandr Byelkin
              lukas.eder Lukas Eder
              Votes:
              1 Vote for this issue
              Watchers:
              7 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.