Details

    • Task
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 10.6.0
    • JSON
    • None

    Description

      MySQL 8.0 has JSON_TABLE. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

      1. Syntax
      1.1 Standard compliance
       
      2. JSON_TABLE as table function
      3. Implementing a table function
      3.1 DDL considerations
      3.2 Producing the rows
      3.3 Interfacing with the optimizer
      3.3.1 Estimates 
      3.3.2 JSON_TABLE must be after its dependencies
      3.3.3 Can't use Join buffering 
      5. Links
      

      1. Syntax

      SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

      The syntax to be implemented is:

        JSON_TABLE(
          json_text,
          path COLUMNS(columns_list) 
        ) [AS] alias
      

      columns_list:  
        column [, column[, ... ]]
      

      column:
          name FOR ORDINALITY 
        | name type PATH path_str [on_empty_on_error]
        | name type EXISTS PATH path_str [on_empty_on_error]
        | NESTED PATH path COLUMNS (columns_list)
      

      on_empty_on_error:
        [ behavior ON EMPTY ] [ behavior ON ERROR ]
      

      behavior:
         ERROR | NULL | DEFAULT <value_expression>
      

      Here, JSON_TABLE(...) is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

      1.1 Standard compliance

      The above is a subset of the syntax allowed by the SQL Standard, with exception of name type EXISTS PATH path_str which is a non-standard extension in (Oracle database and Oracle MySQL?)

      2. JSON_TABLE as table function

      JSON_TABLE is the first table function - a table whose contents depends on its arguments.

      The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

      3. Implementing a table function

      3.1 DDL considerations

      A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

      TODO: At which point should this temporary table be created? It is apparent that this should happen before any Item::fix_fields() calls for the ON/WHERE/etc clauses. It should also happen before Item::fix_fields() calls made for the first parameter of any JSON_TABLE(...).

      3.1.2 Name resolution for JSON_TABLE argument

      The name resolution context should be ... "the same as for the ON expression" ?

      3.2 Producing the rows

      In order to produce rows, a Storage Engine will be implemented, ha_json_table. That is, the temporary table will use the ha_json_table engine.
      (This could be generalized to a generic ha_table_function Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

      The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

      3.3 Interfacing with the optimizer

      3.3.1 Estimates

      The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

      3.3.2 JSON_TABLE must be after its dependencies

      Second, the join optimizer will need to be aware that
      JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
      This will be done as follows:
      Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

      3.3.3 Can't use Join buffering

      Join buffering will be disabled for table JSON_TABLE(...).

      4. Producing JSON_TABLE contents

      4.1 FOR ORDINALITY columns

      The standard says:

      An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.

      The numbering seems to be "global", that is, it doesn't restart across table re-reads.

      4.2 NESTED contents

      The code has a "primary" JSON parser which scans through the JSON document and locates nodes that represent the rows to be produced by JSON_TABLE.
      In order to locate contents of the NESTED construct, we create another instance of JSON parser, point it at the current node, and then let it locate the pointed by the path. It's obvious that this can handle as many NESTED constructs as needed, and the "primary" parser state is not affected by them.

      5. Links

      Attachments

        Issue Links

          Activity

            diego dupin Diego Dupin created issue -
            diego dupin Diego Dupin made changes -
            Field Original Value New Value
            ralf.gebhardt Ralf Gebhardt made changes -
            Component/s JSON [ 13908 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            NRE Projects RM_105_CANDIDATE

            This function will be great to implement

            fduenas Francisco Dueñas added a comment - This function will be great to implement
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 10.5 [ 23123 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Assignee Alexey Botchkov [ holyfoot ]
            holyfoot Alexey Botchkov made changes -
            Due Date 2019-09-02
            serg Sergei Golubchik made changes -
            serg Sergei Golubchik made changes -
            ralf.gebhardt Ralf Gebhardt made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            serg Sergei Golubchik made changes -
            Priority Critical [ 2 ] Major [ 3 ]
            holyfoot Alexey Botchkov made changes -
            Due Date 2019-09-02 2019-11-25
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            julien.fritsch Julien Fritsch made changes -
            Due Date 2019-11-25

            The proper implementation for this task requires adding the new useful thing to MariaDB - table functions. So we'll be able to have functional expressions after the FROM clause.
            To implement this we decided to create the new specific table handler - ha_table_function, that provides the typical HANDLER fucntions so the rest of SELECT implementations will work as usual. Then particular table fucntion implementations can iherit from this base class.
            That way we don't have to create any temporary table with the function result, which would seriously slow the execution.
            Otherwise it's obvious enough how the calculations for particular rows of the JSON_TABLE function should work.

            holyfoot Alexey Botchkov added a comment - The proper implementation for this task requires adding the new useful thing to MariaDB - table functions. So we'll be able to have functional expressions after the FROM clause. To implement this we decided to create the new specific table handler - ha_table_function, that provides the typical HANDLER fucntions so the rest of SELECT implementations will work as usual. Then particular table fucntion implementations can iherit from this base class. That way we don't have to create any temporary table with the function result, which would seriously slow the execution. Otherwise it's obvious enough how the calculations for particular rows of the JSON_TABLE function should work.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2, and PostgreSQL 12

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2, and PostgreSQL 12

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it is not in the 12th release?)

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            Take-aways from discussion:

            A practically-important use case is when JSON_TABLE has arguments that depend on
            another table:

            select ...
            from 
              t1,
              JSON_TABLE(t1.json_field, /* arguments describing which fields to take */)
            where
              ...
            

            This puts some restrictions on the query plans:

            • JSON_TABLE(...) may not precede t1 in the join order
            • - (corollary) outer joins with references from outer side to inner are not
              allowed : have t1 RIGHT JOIN JSON_TABLE(t1.col) ON ...
            • One can't use join buffering for the JSON_TABLE(...) table (at least, without some extra arrangements)

            The property also affects the SE API:

            • when starting a scan, ha_table_function() must get the values of its parameters (either explicitly or implicitly).
            psergei Sergei Petrunia added a comment - Take-aways from discussion: A practically-important use case is when JSON_TABLE has arguments that depend on another table: select ... from t1, JSON_TABLE(t1.json_field, /* arguments describing which fields to take */ ) where ... This puts some restrictions on the query plans: JSON_TABLE(...) may not precede t1 in the join order - (corollary) outer joins with references from outer side to inner are not allowed : have t1 RIGHT JOIN JSON_TABLE(t1.col) ON ... One can't use join buffering for the JSON_TABLE(...) table (at least, without some extra arrangements) The property also affects the SE API: when starting a scan, ha_table_function() must get the values of its parameters (either explicitly or implicitly).

            On limitations:
            The SQL Standard defines A LOT of features for JSON_TABLE. MySQL implements a proper subset of those. It looks like PostgreSQL are also targeting a subset. It should be fine for us to implement a subset, also.

            psergei Sergei Petrunia added a comment - On limitations: The SQL Standard defines A LOT of features for JSON_TABLE. MySQL implements a proper subset of those. It looks like PostgreSQL are also targeting a subset. It should be fine for us to implement a subset, also.

            Another observation: MySQL seems to A) use a temporary table and B) support "ref access" on it:

            mysql> explain SELECT * FROM  JSON_TABLE('[ {"a":111}, {"a":333},{"a":555},{"a":777}]', '$[*]' COLUMNS (a INT PATH '$.a')) AS tt where a=4\G
            *************************** 1. row ***************************
                       id: 1
              select_type: SIMPLE
                    table: tt
               partitions: NULL
                     type: ref
            possible_keys: <auto_key0>
                      key: <auto_key0>
                  key_len: 5
                      ref: const
                     rows: 1
                 filtered: 100.00
                    Extra: Table function: json_table; Using temporary; Using index
            1 row in set, 1 warning (0.00 sec)
            

            mysql> explain SELECT * FROM  JSON_TABLE('[ {"a":111}, {"a":333},{"a":555},{"a":777}]', '$[*]' COLUMNS (a INT PATH '$.a')) AS tt where a<4\G
            *************************** 1. row ***************************
                       id: 1
              select_type: SIMPLE
                    table: tt
               partitions: NULL
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 2
                 filtered: 50.00
                    Extra: Table function: json_table; Using temporary; Using where
            1 row in set, 1 warning (0.00 sec)
            

            I'm not sure how big is the benefit from ref access here (they have to parse the whole JSON text anyway... after that, they can determine that a given row is not a match faster... but still they'll need to read all of the JSON data?)

            psergei Sergei Petrunia added a comment - Another observation: MySQL seems to A) use a temporary table and B) support "ref access" on it: mysql> explain SELECT * FROM JSON_TABLE('[ {"a":111}, {"a":333},{"a":555},{"a":777}]', '$[*]' COLUMNS (a INT PATH '$.a')) AS tt where a=4\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: tt partitions: NULL type: ref possible_keys: <auto_key0> key: <auto_key0> key_len: 5 ref: const rows: 1 filtered: 100.00 Extra: Table function: json_table; Using temporary; Using index 1 row in set, 1 warning (0.00 sec) mysql> explain SELECT * FROM JSON_TABLE('[ {"a":111}, {"a":333},{"a":555},{"a":777}]', '$[*]' COLUMNS (a INT PATH '$.a')) AS tt where a<4\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: tt partitions: NULL type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 2 filtered: 50.00 Extra: Table function: json_table; Using temporary; Using where 1 row in set, 1 warning (0.00 sec) I'm not sure how big is the benefit from ref access here (they have to parse the whole JSON text anyway... after that, they can determine that a given row is not a match faster... but still they'll need to read all of the JSON data?)
            holyfoot Alexey Botchkov made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.5 [ 23123 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            holyfoot Alexey Botchkov added a comment - https://github.com/MariaDB/server/commit/654fdfee33e3eafe3b7f25d7e213717c22ea1e18
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Petrunia [ psergey ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            The patch implements this syntax:

              JSON_TABLE(
                expr,
                path COLUMNS(columns_list) 
              ) AS alias
            

            #note "AS alias" while in other dbs it's just 'alias'?

            columns_list:  
              column [, column[, ... ]]
            

            column:
                name FOR ORDINALITY 
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path_str
              | columns
            

            1. Note: NESTED PATH definition is different from MySQL one.

            Type is a type definition like in the table DDL.

            type: numeric | temporal | string
            

            psergei Sergei Petrunia added a comment - The patch implements this syntax: JSON_TABLE( expr, path COLUMNS(columns_list) ) AS alias #note "AS alias" while in other dbs it's just 'alias'? columns_list: column [, column [, ... ]] column : name FOR ORDINALITY | name type PATH path_str [on_empty] [on_error] | name type EXISTS PATH path_str | NESTED PATH path_str | columns Note: NESTED PATH definition is different from MySQL one. Type is a type definition like in the table DDL. type: numeric | temporal | string
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it is not in the 12th release?)

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it is not in the 12th release?)

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia added a comment - Review for the patch: https://lists.launchpad.net/maria-developers/msg12162.html
            julien.fritsch Julien Fritsch made changes -
            Assignee Sergei Petrunia [ psergey ] Julien Fritsch [ julien.fritsch ]
            julien.fritsch Julien Fritsch made changes -
            Assignee Julien Fritsch [ julien.fritsch ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            psergei Sergei Petrunia added a comment - Second part of the review: https://lists.launchpad.net/maria-developers/msg12172.html
            holyfoot Alexey Botchkov made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it is not in the 12th release?)

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it is not in the 12th release?)

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.


            To implement this we create the new table handler that returns
            the calculated rows. Could be ha_table_function, bug now it's
            the ha_json_table as we don't have other table functions yet.
            The JSON_TABLE creates the temporary table of that ha_json_table
            type. We need to set dep_tables properly so this table is read
            tables mentioned in JSON_TABLE arguments are read, and any
            caching is disallowed for this table.
            holyfoot Alexey Botchkov made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it is not in the 12th release?)

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.


            To implement this we create the new table handler that returns
            the calculated rows. Could be ha_table_function, bug now it's
            the ha_json_table as we don't have other table functions yet.
            The JSON_TABLE creates the temporary table of that ha_json_table
            type. We need to set dep_tables properly so this table is read
            tables mentioned in JSON_TABLE arguments are read, and any
            caching is disallowed for this table.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it is not in the 12th release?)

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.


            To implement this we create the new table handler that returns
            the calculated rows. Could be ha_table_function, bug now it's
            the ha_json_table as we don't have other table functions yet.
            The JSON_TABLE creates the temporary table of that ha_json_table
            type. We need to set dep_tables properly so this table is read
            tables mentioned in JSON_TABLE arguments are read, and any
            caching is disallowed for this table.
            BTW many IS tables can be easily redone with this new handler
            so no need to fill the memory tables.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it is not in the 12th release?)

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.


            To implement this we create the new table handler that returns
            the calculated rows. Could be ha_table_function, bug now it's
            the ha_json_table as we don't have other table functions yet.
            The JSON_TABLE creates the temporary table of that ha_json_table
            type. We need to set dep_tables properly so this table is read
            tables mentioned in JSON_TABLE arguments are read, and any
            caching is disallowed for this table.
            BTW many IS tables can be easily redone with this new handler
            so no need to fill the memory tables.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            h2. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                path_expr,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            h2. JSON_TABLE as table function

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.


            To implement this we create the new table handler that returns
            the calculated rows. Could be ha_table_function, bug now it's
            the ha_json_table as we don't have other table functions yet.
            The JSON_TABLE creates the temporary table of that ha_json_table
            type. We need to set dep_tables properly so this table is read
            tables mentioned in JSON_TABLE arguments are read, and any
            caching is disallowed for this table.
            BTW many IS tables can be easily redone with this new handler
            so no need to fill the memory tables.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            h2. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                path_expr,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            h2. JSON_TABLE as table function

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.


            To implement this we create the new table handler that returns
            the calculated rows. Could be ha_table_function, bug now it's
            the ha_json_table as we don't have other table functions yet.
            The JSON_TABLE creates the temporary table of that ha_json_table
            type. We need to set dep_tables properly so this table is read
            tables mentioned in JSON_TABLE arguments are read, and any
            caching is disallowed for this table.
            BTW many IS tables can be easily redone with this new handler
            so no need to fill the memory tables.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            h2. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                path_expr,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. JSON_TABLE as table function

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.


            To implement this we create the new table handler that returns
            the calculated rows. Could be ha_table_function, bug now it's
            the ha_json_table as we don't have other table functions yet.
            The JSON_TABLE creates the temporary table of that ha_json_table
            type. We need to set dep_tables properly so this table is read
            tables mentioned in JSON_TABLE arguments are read, and any
            caching is disallowed for this table.
            BTW many IS tables can be easily redone with this new handler
            so no need to fill the memory tables.
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            h2. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                path_expr,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. JSON_TABLE as table function

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.

            h2. Other notes
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.


            To implement this we create the new table handler that returns
            the calculated rows. Could be ha_table_function, bug now it's
            the ha_json_table as we don't have other table functions yet.
            The JSON_TABLE creates the temporary table of that ha_json_table
            type. We need to set dep_tables properly so this table is read
            tables mentioned in JSON_TABLE arguments are read, and any
            caching is disallowed for this table.
            BTW many IS tables can be easily redone with this new handler
            so no need to fill the memory tables.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            h2. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                path_expr,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents
            depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which
            causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. Implementing a table function

            h3. DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. Interfacing with the optimizer

            h4. Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            h2. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                path_expr,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents
            depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which
            causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. Implementing a table function

            h3. DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. Interfacing with the optimizer

            h4. Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. Links
            * MySQL: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            4. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                path_expr,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents
            depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which
            causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            4. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                path_expr,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents
            depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which
            causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            4. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents
            depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which
            causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            4. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents
            depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which
            causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str [on_empty] [on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty] [on_error]
              | name type EXISTS PATH path_str [on_empty] [on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}}
            engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia added a comment - Review part #4: https://lists.launchpad.net/maria-developers/msg12225.html

            Notes to self (for next review iteration)

            • we will need EXPLAIN to indicate that a table function is used.
            • JSON_TABLE inside a re-usable CTEs seems to work but I don't quite understand how
            psergei Sergei Petrunia added a comment - Notes to self (for next review iteration) we will need EXPLAIN to indicate that a table function is used. JSON_TABLE inside a re-usable CTEs seems to work but I don't quite understand how
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Petrunia [ psergey ]
            Status Stalled [ 10000 ] In Review [ 10002 ]

            Interesting, this query

            select * 
            from 
              json_table('[{"color": "blue", "price": 50},
                           {"color": "red"}]',
                         '$[*]' columns( price varchar(255) path '$.price' default 'aaa' on empty )) as T;
            

            produces an error in MySQL 8:

            ERROR 3141 (22032): Invalid JSON text in argument 1 to function JSON_TABLE: "Invalid value." at position 0.
            

            But runs successfully in Oracle 18c: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=af4084b9b8abc04281bc5effa6d10249 .

            It runs in MariaDB, too.

            psergei Sergei Petrunia added a comment - Interesting, this query select * from json_table( '[{"color": "blue", "price": 50}, {"color": "red"}]' , '$[*]' columns( price varchar (255) path '$.price' default 'aaa' on empty )) as T; produces an error in MySQL 8: ERROR 3141 (22032): Invalid JSON text in argument 1 to function JSON_TABLE: "Invalid value." at position 0. But runs successfully in Oracle 18c: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=af4084b9b8abc04281bc5effa6d10249 . It runs in MariaDB, too.

            Another observation is that Oracle allows DEFAULT's value-expression to be, for example, integer:

            select * 
            from 
              json_table('[{"color": "blue", "price": 50},
                           {"color": "red"}]',
                         '$[*]' columns( price int path '$.price' default 12345 on empty )) as T;
            

            while MySQL 8 does not.

            I'm reading the part of the standard this MDEV links to, and it has this:

            <JSON table column empty behavior> ::=
            ERROR
            | NULL
            | DEFAULT <value expression>
            

            but I don't see anything about what type <value expression> should have. Interesting that NULL is mentioned separately, this means <value expression> cannot be NULL?

            psergei Sergei Petrunia added a comment - Another observation is that Oracle allows DEFAULT's value-expression to be, for example, integer: select * from json_table( '[{"color": "blue", "price": 50}, {"color": "red"}]' , '$[*]' columns( price int path '$.price' default 12345 on empty )) as T; while MySQL 8 does not. I'm reading the part of the standard this MDEV links to, and it has this: <JSON table column empty behavior> ::= ERROR | NULL | DEFAULT <value expression> but I don't see anything about what type <value expression> should have. Interesting that NULL is mentioned separately, this means <value expression> cannot be NULL?
            psergei Sergei Petrunia added a comment - - edited

            there's this:

            Feature T826, “General value expression in ON ERROR or ON EMPTY clauses”
            •
            Without this feature, the user specified value expression in the ON ERROR clause or ON EMPTY
            clause in JSON_VALUE or on a regular column definition in JSON_TABLE can only be a literal.

            So,

            • Generally, these expressions dont have to be literal
            • We can impose a limitation that they are literals.
            • As far as I understand, "literal" includes string/integer/etc literals. So, the current patch imposes an additional limitation by supporting only string literals.
            psergei Sergei Petrunia added a comment - - edited there's this: Feature T826, “General value expression in ON ERROR or ON EMPTY clauses” • Without this feature, the user specified value expression in the ON ERROR clause or ON EMPTY clause in JSON_VALUE or on a regular column definition in JSON_TABLE can only be a literal. So, Generally, these expressions dont have to be literal We can impose a limitation that they are literals. As far as I understand, "literal" includes string/integer/etc literals. So, the current patch imposes an additional limitation by supporting only string literals.
            psergei Sergei Petrunia added a comment - Review input part #5 : https://www.mail-archive.com/maria-developers@lists.launchpad.net/msg11827.html
            psergei Sergei Petrunia added a comment - Review input part #6: https://lists.launchpad.net/maria-developers/msg12295.html
            psergei Sergei Petrunia added a comment - Also, a question: https://lists.launchpad.net/maria-developers/msg12296.html
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            holyfoot Alexey Botchkov made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Petrunia [ psergey ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            psergei Sergei Petrunia added a comment - Review input part #7: https://lists.launchpad.net/maria-developers/msg12334.html Review input part #8: https://lists.launchpad.net/maria-developers/msg12336.html
            psergei Sergei Petrunia added a comment - Review input part #9: https://lists.launchpad.net/maria-developers/msg12344.html
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * SQL:2016, as well as SQL Standard drafts from as early as 2014-11-10 cover JSON_TABLE.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)
             
            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * SQL:2016, as well as SQL Standard drafts from as early as 2014-11-10 cover JSON_TABLE.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            1.1 Standard compliance

            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)

            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * SQL:2016, as well as SQL Standard drafts from as early as 2014-11-10 cover JSON_TABLE.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.

            Followup to optimizer call on Tuesday:

            SQL Standard, section 7.6 <table reference>:

            <table primary> ::=
            <table or query name>
            [ <query system time period specification> ]
            [ <correlation or recognition> ]
            | <derived table> <correlation or recognition>
            | <lateral derived table> <correlation or recognition>
            | <collection derived table> <correlation or recognition>
            | <table function derived table> <correlation or recognition>
            | <only spec> [ <correlation or recognition> ]
            | <data change delta table> [ <correlation or recognition> ]
            | <JSON table> <correlation or recognition>
            | <JSON table primitive> <correlation name>
            | <parenthesized joined table>
            

            <table function derived table> ::=
            TABLE <left paren> <collection value expression> <right paren>
            

            Section 7.11 <JSON table>:

            <JSON table> ::=
              JSON_TABLE <left paren> ....... <right paren>
            

            That is, JSON_TABLE and TABLE (...) are two different productions that have nothing in common.

            psergei Sergei Petrunia added a comment - Followup to optimizer call on Tuesday: SQL Standard, section 7.6 <table reference>: <table primary> ::= <table or query name> [ <query system time period specification> ] [ <correlation or recognition> ] | <derived table> <correlation or recognition> | <lateral derived table> <correlation or recognition> | <collection derived table> <correlation or recognition> | <table function derived table> <correlation or recognition> | <only spec> [ <correlation or recognition> ] | <data change delta table> [ <correlation or recognition> ] | <JSON table> <correlation or recognition> | <JSON table primitive> <correlation name> | <parenthesized joined table> <table function derived table> ::= TABLE <left paren> <collection value expression> <right paren> Section 7.11 <JSON table>: <JSON table> ::= JSON_TABLE <left paren> ....... <right paren> That is, JSON_TABLE and TABLE (...) are two different productions that have nothing in common.
            serg Sergei Golubchik made changes -
            Rank Ranked higher
            julien.fritsch Julien Fritsch made changes -
            Assignee Sergei Petrunia [ psergey ] Julien Fritsch [ julien.fritsch ]
            julien.fritsch Julien Fritsch made changes -
            Assignee Julien Fritsch [ julien.fritsch ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            rdyas Robert Dyas added a comment - - edited

            I would really like to see this implemented with json_text being able to be an S3 bucket reference as follows:

            JSON_TABLE(
                json_text | 's3://my-bucket/path',
                path COLUMNS(columns_list) 
              ) [AS] alias
            

            This would make it super easy to stage lots of large json log files in an S3 bucket and then injest them into column store with a command like CREATE TABLE blah AS SELECT * FROM JSON_TABLE('s3://my-bucket/path', ....).

            rdyas Robert Dyas added a comment - - edited I would really like to see this implemented with json_text being able to be an S3 bucket reference as follows: JSON_TABLE( json_text | 's3://my-bucket/path' , path COLUMNS(columns_list) ) [ AS ] alias This would make it super easy to stage lots of large json log files in an S3 bucket and then injest them into column store with a command like CREATE TABLE blah AS SELECT * FROM JSON_TABLE('s3://my-bucket/path', ....).
            rdyas Robert Dyas added a comment -

            Also, while we are at it, it would be very nice to have a CSV_TABLE function with similar syntax such that

            CREATE TABLE t1 AS SELECT * FROM CSV_TABLE('s3://bucket/mycsvfile.csv', ...)  

            With the path COLUMNS(columns_list) argument taking a list of columns in the CSV file. Great way of injecting large CSV files from S3 into column store.

            rdyas Robert Dyas added a comment - Also, while we are at it, it would be very nice to have a CSV_TABLE function with similar syntax such that CREATE TABLE t1 AS SELECT * FROM CSV_TABLE('s3://bucket/mycsvfile.csv', ...)   With the path COLUMNS(columns_list) argument taking a list of columns in the CSV file. Great way of injecting large CSV files from S3 into column store.

            The functionality to get data from a CSV file already exists using CONNECT engine.
            Althought it is not as dynamic as JSON_TABLE (or CSV_TABLE), you can create a Stored Procedure to read data from a CSV file by creating a virtual table that reads CSV data.

            Check the CONNECT engine documentation for more info.

            fduenas Francisco Dueñas added a comment - The functionality to get data from a CSV file already exists using CONNECT engine. Althought it is not as dynamic as JSON_TABLE (or CSV_TABLE), you can create a Stored Procedure to read data from a CSV file by creating a virtual table that reads CSV data. Check the CONNECT engine documentation for more info.
            rdyas Robert Dyas added a comment -

            from an s3 bucket efficiently ? lots of experience with CONNECT engine and
            performance is not its strength. this needs to be efficient for ingesting
            LOTS of data from s3 into columnstore.

            On Tue, Sep 22, 2020, 10:19 PM Francisco Dueñas (Jira) <jira@mariadb.org>

            rdyas Robert Dyas added a comment - from an s3 bucket efficiently ? lots of experience with CONNECT engine and performance is not its strength. this needs to be efficient for ingesting LOTS of data from s3 into columnstore. On Tue, Sep 22, 2020, 10:19 PM Francisco Dueñas (Jira) <jira@mariadb.org>
            holyfoot Alexey Botchkov added a comment - https://github.com/MariaDB/server/commit/fbcd1908ebb9278e2a073341c18f4e896fda2e1d
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Petrunia [ psergey ]
            Status Stalled [ 10000 ] In Review [ 10002 ]

            If table functions are going to be added, making the interface generic such that UDF table functions and/or using stored routines as table functions (since they can return resultsets) would be really nice. Perhaps that should be a prequisite MDEV for this feature?

            greenlion Justin Swanhart added a comment - If table functions are going to be added, making the interface generic such that UDF table functions and/or using stored routines as table functions (since they can return resultsets) would be really nice. Perhaps that should be a prequisite MDEV for this feature?

            greenlion, one problem with developing generic interfaces is answering the question what should be supported. Taking Stored Routines as an example - we won't be able have an "opaque" table function that calls SPs in it, due to the process called "prelocking".

            The big decision that this MDEV code has made is that the table function also uses a table handler to provide rows. This allows for interesting opportunities like pushing conditions down into table functions, and/or table functions' tables providing indexes.

            Compare that to MySQL's implementation - they just fill a temporary table and then read from there (an example stack trace : https://gist.github.com/spetrunia/1c38564a7ead92562fd984cbf48c0655) . OTOH, using a temporary may make some implementation simpler - one doesn't need to support ::position or ::rnd_pos.)

            psergei Sergei Petrunia added a comment - greenlion , one problem with developing generic interfaces is answering the question what should be supported. Taking Stored Routines as an example - we won't be able have an "opaque" table function that calls SPs in it, due to the process called "prelocking". The big decision that this MDEV code has made is that the table function also uses a table handler to provide rows. This allows for interesting opportunities like pushing conditions down into table functions, and/or table functions' tables providing indexes. Compare that to MySQL's implementation - they just fill a temporary table and then read from there (an example stack trace : https://gist.github.com/spetrunia/1c38564a7ead92562fd984cbf48c0655 ) . OTOH, using a temporary may make some implementation simpler - one doesn't need to support ::position or ::rnd_pos.)

            On some previous optimizer call, I was asked if MySQL's way of making Table Function's columns available for Name Resolution is any different from MariaDB's.

            Did some debugging and the answer is NO. Both use the same approach: create a temporary table (incl. a TABLE object), and then the TABLE_LIST representing the table function has table_list->table pointing to the created table, which allows Name Resolution functions to work as usual. A Table Function call is just another base table for it.

            psergei Sergei Petrunia added a comment - On some previous optimizer call, I was asked if MySQL's way of making Table Function's columns available for Name Resolution is any different from MariaDB's. Did some debugging and the answer is NO. Both use the same approach: create a temporary table (incl. a TABLE object), and then the TABLE_LIST representing the table function has table_list->table pointing to the created table, which allows Name Resolution functions to work as usual. A Table Function call is just another base table for it.
            greenlion Justin Swanhart added a comment - - edited

            @sergeyp

            This is just a suggestion. I think a stored proc interface could be created like:
            This is pseudo code where TABLE_FUNC(X, Y, Z) is the stored table function

            -- creates a temporary table and returns the fully qualified temporary table name that stored table function results will be stored in
            create stored function table_func_init() RETURNS string
              -- mariadb could provide a optional function GENERATE_TMP_TABLE_NAME() that generates random table names
              set @tmp_table_name = GENERATE_TMP_TABLE_NAME();
              prepare stmt from concat('create temporary table ', @tmp_table_name, ' ( ....)');;
              exec stmt;
              deallocate prepare stmt;
              return temporary_table_name;
            end;;
             
              -- clears the table function temporary table before each call [for each row input to the function]
            create stored function table_func_clear(TABLE_NAME)
              -- truncate or delete the contents of the temporary table
            end;;
             
            create stored function table_func_deinit(TABLE_NAME)
             -- drop the temporary table
            end;;
             
            create stored function table_func(table_name, x, y, z)
              -- populate table_name with results for x, y, z params
            end;
            

            Then for select * from TABLE_FUNC(x,y,z) , some_table the query execution engine does:

            table_func_init is called at parse and returns temp table name
            for each row
              table_func_clear(...) -- removes rows from temp table
              table_func(x,y,z) -- populates temp table
              -- iterate temporary_table with rnd_init, rnd_next, rnd_end
            end for each row;;
             
            table_func_deinit(TABLE_NAME) -- cleanup
              set @drop_stmt = concat('drop temporary table ', TABLE_NAME);
            end;; 
             
              prepare stmt from @drop_stmt
            

            Just a thought, but that seems like a reasonably flexible interface that will support arbitrary table functions.}}

            as for "prelocking" any tables used in the init func, clear func, or the func itself, as well as the temporary table being used, can be locked just like normal stored functions. all the table names are known at parse time in this case... I think that satisfies the requirements for prelocking. Please correct me if I'm wrong.

            greenlion Justin Swanhart added a comment - - edited @sergeyp This is just a suggestion. I think a stored proc interface could be created like: This is pseudo code where TABLE_FUNC(X, Y, Z) is the stored table function -- creates a temporary table and returns the fully qualified temporary table name that stored table function results will be stored in create stored function table_func_init() RETURNS string -- mariadb could provide a optional function GENERATE_TMP_TABLE_NAME() that generates random table names set @tmp_table_name = GENERATE_TMP_TABLE_NAME(); prepare stmt from concat('create temporary table ', @tmp_table_name, ' ( ....)');; exec stmt; deallocate prepare stmt; return temporary_table_name; end;;   -- clears the table function temporary table before each call [for each row input to the function] create stored function table_func_clear(TABLE_NAME) -- truncate or delete the contents of the temporary table end;;   create stored function table_func_deinit(TABLE_NAME) -- drop the temporary table end;;   create stored function table_func(table_name, x, y, z) -- populate table_name with results for x, y, z params end; Then for select * from TABLE_FUNC(x,y,z) , some_table the query execution engine does: table_func_init is called at parse and returns temp table name for each row table_func_clear(...) -- removes rows from temp table table_func(x,y,z) -- populates temp table -- iterate temporary_table with rnd_init, rnd_next, rnd_end end for each row;;   table_func_deinit(TABLE_NAME) -- cleanup set @drop_stmt = concat('drop temporary table ', TABLE_NAME); end;;   prepare stmt from @drop_stmt Just a thought, but that seems like a reasonably flexible interface that will support arbitrary table functions.}} as for "prelocking" any tables used in the init func, clear func, or the func itself, as well as the temporary table being used, can be locked just like normal stored functions. all the table names are known at parse time in this case... I think that satisfies the requirements for prelocking. Please correct me if I'm wrong.
            psergei Sergei Petrunia added a comment - holyfoot , review input: https://lists.launchpad.net/maria-developers/msg12465.html https://lists.launchpad.net/maria-developers/msg12466.html
            psergei Sergei Petrunia added a comment - More: https://lists.launchpad.net/maria-developers/msg12467.html
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            1.1 Standard compliance

            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)

            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * SQL:2016, as well as SQL Standard drafts from as early as 2014-11-10 cover JSON_TABLE.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            1.1 Standard compliance

            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)

            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h4 3.1.1 Steps

            TODO: How about references to columns of JSON_TABLE(...) which are not yet created? It possible?

            h4. 3.1.2

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * SQL:2016, as well as SQL Standard drafts from as early as 2014-11-10 cover JSON_TABLE.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia made changes -
            Description MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            1.1 Standard compliance

            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)

            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            h4 3.1.1 Steps

            TODO: How about references to columns of JSON_TABLE(...) which are not yet created? It possible?

            h4. 3.1.2

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * SQL:2016, as well as SQL Standard drafts from as early as 2014-11-10 cover JSON_TABLE.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            MySQL 8.0 has [JSON_TABLE|https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html]. These is also available in Oracle, DB2. (PostgreSQL has a patch under development but it seems it is not in the 12th or 13th release)

            {code}
            1. Syntax
            1.1 Standard compliance

            2. JSON_TABLE as table function
            3. Implementing a table function
            3.1 DDL considerations
            3.2 Producing the rows
            3.3 Interfacing with the optimizer
            3.3.1 Estimates
            3.3.2 JSON_TABLE must be after its dependencies
            3.3.3 Can't use Join buffering
            5. Links
            {code}

            h2. 1. Syntax

            SQL Standard defines a lot of features for JSON_TABLE. This task will implement a practically-important subset (roughly the same what MySQL-8 supports)

            The syntax to be implemented is:

            {code:sql}
              JSON_TABLE(
                json_text,
                path COLUMNS(columns_list)
              ) [AS] alias
            {code}

            {code:sql}
            columns_list:
              column [, column[, ... ]]
            {code}

            {code:sql}
            column:
                name FOR ORDINALITY
              | name type PATH path_str [on_empty_on_error]
              | name type EXISTS PATH path_str [on_empty_on_error]
              | NESTED PATH path COLUMNS (columns_list)
            {code}

            {code}
            on_empty_on_error:
              [ behavior ON EMPTY ] [ behavior ON ERROR ]
            {code}

            {code}
            behavior:
               ERROR | NULL | DEFAULT <value_expression>
            {code}

            Here, {{JSON_TABLE(...)}} is a table function and is allowed wherever a table reference is allowed, except for the context which imply that the referred table is to be modified.

            h3. 1.1 Standard compliance
            The above is a subset of the syntax allowed by the SQL Standard, with exception of {{name type EXISTS PATH path_str}} which is a non-standard extension in (Oracle database and Oracle MySQL?)

            h2. 2. JSON_TABLE as table function
            JSON_TABLE is the first *table function* - a table whose contents depends on its arguments.

            The arguments may be non-constant (e.g. columns of other tables), which causes the JSON_TABLE table to have LATERAL-like dependencies on its arguments.

            h2. 3. Implementing a table function

            h3. 3.1 DDL considerations

            A temporary table [definition] will be created with appropriate set of columns with appropriate attributes. This will allow for references to the columns of JSON_TABLE(...) to be resolved using the regular name resolution process.

            TODO: At which point should this temporary table be created? It is apparent that this should happen before any Item::fix_fields() calls for the ON/WHERE/etc clauses. It should also happen before Item::fix_fields() calls made for the first parameter of any JSON_TABLE(...).

            h4. 3.1.2 Name resolution for JSON_TABLE argument

            The name resolution context should be ... "the same as for the ON expression" ?

            h3. 3.2 Producing the rows

            In order to produce rows, a Storage Engine will be implemented, {{ha_json_table}}. That is, the temporary table will use the {{ha_json_table}} engine.
            (This could be generalized to a generic {{ha_table_function}} Storage Engine for table function, but it was decided not to do that until we have other examples of table functions).

            The engine will only support full table scans (rnd_init/rnd_next). rnd_init() call will implicitly evaluate the JSON_TABLE's parameters and set the storage engine to produce the rows that come from the parameters.

            h3. 3.3 Interfacing with the optimizer

            h4. 3.3.1 Estimates
            The optimizer will need to be aware that the table representing the output of JSON_TABLE(...) does not have any contents during the optimization phase. We will still need to provide some numbers for expected #rows and read_time. JSON documents are typically small, so a hard-coded constant describing a reasonably-sized JSON document would be sufficient.

            h4. 3.3.2 JSON_TABLE must be after its dependencies
            Second, the join optimizer will need to be aware that
            JSON_TABLE(tbl1.column_x, ... ) can only be accessed when the current row for table tbl1 is available.
            This will be done as follows:
            Table dependencies will be set such that JSON_TABLE(...) depends on tbl1.

            h4. 3.3.3 Can't use Join buffering
            Join buffering will be disabled for table JSON_TABLE(...).

            h2. 4. Producing JSON_TABLE contents

            h3. 4.1 FOR ORDINALITY columns
            The standard says:
            {quote}
            An ordinality column provides a sequential numbering of rows. Row numbering is 1-based.
            {quote}
            The numbering seems to be "global", that is, it doesn't restart across table re-reads.

            h3. 4.2 NESTED contents

            The code has a "primary" JSON parser which scans through the JSON document and locates nodes that represent the rows to be produced by JSON_TABLE.
            In order to locate contents of the NESTED construct, we create another instance of JSON parser, point it at the current node, and then let it locate the pointed by the path. It's obvious that this can handle as many NESTED constructs as needed, and the "primary" parser state is not affected by them.

            h2. 5. Links
            * JSON_TABLE in MySQL-8: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
            * SQL Standard: This page https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
            has a link to http://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip
            which in section 5.3.4 has a specification for JSON_TABLE function.
            * SQL:2016, as well as SQL Standard drafts from as early as 2014-11-10 cover JSON_TABLE.
            * PostgreSQL were working on this, see e.g. https://pgconf.ru/media/2019/02/20/postgresql-12-pgconfru-2019-v2.pdf , but currently they don't seem to have this.
            psergei Sergei Petrunia added a comment - - edited

            Interesting, MySQL has this limitation: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html

            expr: This is an expression that returns JSON data. This can be a constant ('{"a":1}'), a column (t1.json_data, given table t1 specified prior to JSON_TABLE() in the FROM clause) ...

            This frees them from the need to detect circular dependencies:

            • one cannot construct a loop of JSON_TABLE referring to each other
            • one cannot construct a JSON_TABLE dependency contradicting LEFT JOIN , STRAIGHT JOIN or RIGHT JOIN dependencies ( for RIGHT JOIN, the left and right sides are swapped at the parser level).

            I cannot find any mention of such limitation in the SQL Standard, though.

            AFAIU, something like this could be supported:

            create table t11 (a varchar(10));
            select * from 
              json_table(t11.a, '$[*]' COLUMNS (id INT PATH '$')) AS OT1,
              t11
            

            but it is not.

            psergei Sergei Petrunia added a comment - - edited Interesting, MySQL has this limitation: https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html expr: This is an expression that returns JSON data. This can be a constant ('{"a":1}'), a column (t1.json_data, given table t1 specified prior to JSON_TABLE() in the FROM clause ) ... This frees them from the need to detect circular dependencies: one cannot construct a loop of JSON_TABLE referring to each other one cannot construct a JSON_TABLE dependency contradicting LEFT JOIN , STRAIGHT JOIN or RIGHT JOIN dependencies ( for RIGHT JOIN, the left and right sides are swapped at the parser level). I cannot find any mention of such limitation in the SQL Standard, though. AFAIU, something like this could be supported: create table t11 (a varchar (10)); select * from json_table(t11.a, '$[*]' COLUMNS (id INT PATH '$' )) AS OT1, t11 but it is not.
            psergei Sergei Petrunia added a comment - - edited

            Note: name resolution does not seem to be "like in an ON expression".
            Here is an example:

            create table t10 (a varchar(10));
            create table t11 (a varchar(10));
             select * 
             from 
              t10 join  
              ( t11 join 
                 json_table(t10.a, '$[*]' COLUMNS (id INT PATH '$')) AS OT1
                 on t11.a is not null /* and t10.a is not null */
               ) 
              on t10.a is not null;
            

            referring to t10.a as an argument to JSON_TABLE is accepted, but if one un-comments t10.a is not null, that produces an error.

            psergei Sergei Petrunia added a comment - - edited Note: name resolution does not seem to be "like in an ON expression". Here is an example: create table t10 (a varchar (10)); create table t11 (a varchar (10)); select * from t10 join ( t11 join json_table(t10.a, '$[*]' COLUMNS (id INT PATH '$' )) AS OT1 on t11.a is not null /* and t10.a is not null */ ) on t10.a is not null ; referring to t10.a as an argument to JSON_TABLE is accepted, but if one un-comments t10.a is not null , that produces an error.
            julien.fritsch Julien Fritsch made changes -
            julien.fritsch Julien Fritsch made changes -
            Assignee Sergei Petrunia [ psergey ] Alexey Botchkov [ holyfoot ]
            julien.fritsch Julien Fritsch made changes -
            Assignee Alexey Botchkov [ holyfoot ] Julien Fritsch [ julien.fritsch ]
            julien.fritsch Julien Fritsch made changes -
            Assignee Julien Fritsch [ julien.fritsch ] Alexey Botchkov [ holyfoot ]

            ... well, Oracle 18C is a bad example, as it also allows cases that we didn't want to allow:

             
            create table t1 (item_name varchar(32), item_props varchar(1024));
            insert into t1 values ('Laptop', '{"color": "black", "price": 1000}');
             
            select * 
            from
              t1 right join json_table(t1.item_props,
                                       '$' columns( color varchar(100) path '$.color')
                                       ) as T  on t1.item_name=T.color ;
            -- This should produce an error
            -- But it is accepted and produces an empty set.
            

            psergei Sergei Petrunia added a comment - ... well, Oracle 18C is a bad example, as it also allows cases that we didn't want to allow:   create table t1 (item_name varchar(32), item_props varchar(1024)); insert into t1 values ('Laptop', '{"color": "black", "price": 1000}');   select * from t1 right join json_table(t1.item_props, '$' columns( color varchar(100) path '$.color') ) as T on t1.item_name=T.color ; -- This should produce an error -- But it is accepted and produces an empty set.
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Petrunia [ psergey ]
            psergei Sergei Petrunia added a comment - Review input for the last version of the patch: https://lists.launchpad.net/maria-developers/msg12521.html https://lists.launchpad.net/maria-developers/msg12522.html https://lists.launchpad.net/maria-developers/msg12523.html https://lists.launchpad.net/maria-developers/msg12524.html https://lists.launchpad.net/maria-developers/msg12525.html https://lists.launchpad.net/maria-developers/msg12526.html

            As for name resolution, the closest thing the SQL standard has to say is section 7.6 <table reference>,
            p 418:

            If TR is simply contained in a <from clause> FC, then the scope of the range variables of TR is every
            <lateral derived table> that is simply contained in FC and is preceded by TR, and every <collection
            derived table> that is simply contained in FC and is preceded by TR, and every <table function derived
            table> that is simply contained in FC and is preceded by TR, and the <join condition> of all <joined
            table>s contained in FC that contain TR.

            That is, Table Reference is visible in every <lateral derived table> that follows it.
            The same for <collection derived table>.
            The same for <table function derived table>.

            Note that the above list does NOT include JSON_TABLE:

             <table primary> ::=
              ...
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              ...
              | <JSON table> <correlation or recognition>
            

            psergei Sergei Petrunia added a comment - As for name resolution, the closest thing the SQL standard has to say is section 7.6 <table reference>, p 418: If TR is simply contained in a <from clause> FC, then the scope of the range variables of TR is every <lateral derived table> that is simply contained in FC and is preceded by TR, and every <collection derived table> that is simply contained in FC and is preceded by TR, and every <table function derived table> that is simply contained in FC and is preceded by TR, and the <join condition> of all <joined table>s contained in FC that contain TR. That is, Table Reference is visible in every <lateral derived table> that follows it. The same for <collection derived table>. The same for <table function derived table>. Note that the above list does NOT include JSON_TABLE: <table primary> ::= ... | <lateral derived table> <correlation or recognition> | <collection derived table> <correlation or recognition> | <table function derived table> <correlation or recognition> ... | <JSON table> <correlation or recognition>

            More review input: https://lists.launchpad.net/maria-developers/msg12531.html

            I don't have any other input for now, need to take another look after things reported so far have been addressed.

            psergei Sergei Petrunia added a comment - More review input: https://lists.launchpad.net/maria-developers/msg12531.html I don't have any other input for now, need to take another look after things reported so far have been addressed.
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            holyfoot Alexey Botchkov added a comment - https://github.com/MariaDB/server/commit/4d2f5a23de4304d756263d2f170889c586a48680
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Petrunia [ psergey ]
            Status Stalled [ 10000 ] In Review [ 10002 ]
            psergei Sergei Petrunia added a comment - The latest patch was: https://github.com/MariaDB/server/commit/85757ecbef44484270e385a8d52998c67f72d11a Review input for it: https://lists.launchpad.net/maria-developers/msg12539.html

            Pushed the fix for the last issue, and another code cleanup fix.
            Re-based on the latest 10.6
            Post-rebase fix for json_table_mysql.test

            The result is at: https://github.com/mariadb/server/tree/bb-10.6-mdev17399-psergey2

            psergei Sergei Petrunia added a comment - Pushed the fix for the last issue, and another code cleanup fix. Re-based on the latest 10.6 Post-rebase fix for json_table_mysql.test The result is at: https://github.com/mariadb/server/tree/bb-10.6-mdev17399-psergey2
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            julien.fritsch Julien Fritsch made changes -
            Assignee Alexey Botchkov [ holyfoot ] Elena Stepanova [ elenst ]
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            psergei Sergei Petrunia made changes -
            ralf.gebhardt Ralf Gebhardt made changes -
            elenst Elena Stepanova made changes -

            The last round of tests on https://github.com/MariaDB/server/commit/c3cb41111c4bf27c5b0f378a4c5283956d34ed52 didn't reveal any significant issues related to the scope of the task. In my opinion it can be released with a beta-version of the server.

            elenst Elena Stepanova added a comment - The last round of tests on https://github.com/MariaDB/server/commit/c3cb41111c4bf27c5b0f378a4c5283956d34ed52 didn't reveal any significant issues related to the scope of the task. In my opinion it can be released with a beta-version of the server.
            elenst Elena Stepanova made changes -
            Assignee Elena Stepanova [ elenst ] Sergei Petrunia [ psergey ]
            psergei Sergei Petrunia made changes -
            Fix Version/s 10.6.0 [ 24431 ]
            Fix Version/s 10.6 [ 24028 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            greenman Ian Gilfillan made changes -

            This is a great feature. Will make a lot of people happy.

            On Mon, Apr 26, 2021, 12:57 PM Sergei Petrunia (Jira) <jira@mariadb.org>

            greenlion Justin Swanhart added a comment - This is a great feature. Will make a lot of people happy. On Mon, Apr 26, 2021, 12:57 PM Sergei Petrunia (Jira) <jira@mariadb.org>
            markus makela markus makela made changes -
            deepak deepak made changes -
            GeoffMontee Geoff Montee (Inactive) made changes -
            ralf.gebhardt Ralf Gebhardt made changes -
            ralf.gebhardt Ralf Gebhardt made changes -
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 89978 ] MariaDB v4 [ 133710 ]
            alice Alice Sherepa made changes -
            ralf.gebhardt Ralf Gebhardt made changes -
            Epic Link MDEV-17397 [ 70163 ]
            bar Alexander Barkov made changes -

            People

              psergei Sergei Petrunia
              diego dupin Diego Dupin
              Votes:
              31 Vote for this issue
              Watchers:
              32 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.