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

query the metadata of a dynamic column

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • Dynamic Columns
    • None

    Description

      The set of SQL functions for dynamic columns is missing a way to query the metadata of a dynamic column. Like, what type a particular column has, number of columns, and so on. There can also be a function to return both the value and a type as an SQL-compatible cast:

      SELECT COLUMN_GET_SQL(dyncol, 'a') FROM t1;
      +-------------------------------+
      | COLUMN_GET_SQL(dyncol, 'a')   |
      +-------------------------------+
      | CAST(123.45 AS DECIMAL(10,2)) |
      +-------------------------------+

      Attachments

        Issue Links

          Activity

            thefsb Tom added a comment -

            I think this is nice for completeness but is probably not very practical.

            I work with the Yii 2.0 Active Record ORM. This ORM has no configuration. It reads a table description from the server and uses it to relate object properties with table column names, datatypes and values. My work attempts to extend this ORM to dynamic columns yii2-dynamic-ar and has three main parts:

            1. Saving models to table records
            2. Loading table records into models
            3. Allowing individual dynamic columns to be used in queries, e.g. in a WHERE condition

            2. is the hardest because, unlike normal columns, the ORM doesn't know anything about the content of dyncol_blobs. COLUMN_JSON() is convenient because it can load the whole dyncol_blob at once. But if I rely on it then I have to avoid using BINARY in a dynamic column (JSON can represent only valid Unicode strings) and avoid non-Unicode column names. Let's see how could I use COLUMN_GET_SQL() to overcome this limitation...

            First the ORM would use COLUMN_LIST() to get dynamic column names. In the next query, it would use a number of COLUMN_GET_SQL() expressions to load datatypes and values. COLUMN_GET_SQL() would somehow indicate if a dynamic column itself contains a dyncol_blob, in which case the ORM makes two more queries to load first the names and then the types/values, and it keeps iterating like this down the data structure tree until it has everything.

            You can imagine how I don't think this is very practical.

            Alternatives:

            1. COLUMN_GET_SQL(dyncol_blob) without the column name to that returns a possibly long, possibly nested COLUMN_CREATE() expression (with casts).
            2. Follow the example of SHOW CREATE TABLE. I haven't worked out any details but it would return a table of strings which describe everything in the dyncol_blob: structure, column names, datatypes, values. It would use the standard client protocol to return the table.
            3. Use the same serialization that mysqldump uses for dynamic columns.
            4. Give up and impelment a new protocol, e.g. MongoDB's BSON, or Google's Protocol Buffers.

            I like the 2. best. 1. requires me to write an SQL parser. 3. Requires standardizing (and probably versioning) the internal blob encoding. 4. is radical. 2 uses current protocols and is easy to live with. Perhaps:

            > SELECT COLUMN_GET_ALL(`specification`) FROM `product`;
            +--------------+--------------+------------+
            | Name         | Datatype     | Value      |
            +--------------+--------------+------------+
            | category     | CHAR         | Transistor |
            | description  | CHAR         | TO-91      |
            | manufacturer | CHAR         | Fairchild  |
            | price        | BLOB         | NULL       |
            | price.unit   | DECIMAL(9,5) | 0.03315    |
            | price.100    | DECIMAL(9,5) | 2.45000    |
            +--------------+--------------+------------+

            thefsb Tom added a comment - I think this is nice for completeness but is probably not very practical. I work with the Yii 2.0 Active Record ORM . This ORM has no configuration. It reads a table description from the server and uses it to relate object properties with table column names, datatypes and values. My work attempts to extend this ORM to dynamic columns yii2-dynamic-ar and has three main parts: Saving models to table records Loading table records into models Allowing individual dynamic columns to be used in queries, e.g. in a WHERE condition 2. is the hardest because, unlike normal columns, the ORM doesn't know anything about the content of dyncol_blobs. COLUMN_JSON() is convenient because it can load the whole dyncol_blob at once. But if I rely on it then I have to avoid using BINARY in a dynamic column (JSON can represent only valid Unicode strings) and avoid non-Unicode column names. Let's see how could I use COLUMN_GET_SQL() to overcome this limitation... First the ORM would use COLUMN_LIST() to get dynamic column names. In the next query, it would use a number of COLUMN_GET_SQL() expressions to load datatypes and values. COLUMN_GET_SQL() would somehow indicate if a dynamic column itself contains a dyncol_blob, in which case the ORM makes two more queries to load first the names and then the types/values, and it keeps iterating like this down the data structure tree until it has everything. You can imagine how I don't think this is very practical. Alternatives: COLUMN_GET_SQL(dyncol_blob) without the column name to that returns a possibly long, possibly nested COLUMN_CREATE() expression (with casts). Follow the example of SHOW CREATE TABLE. I haven't worked out any details but it would return a table of strings which describe everything in the dyncol_blob: structure, column names, datatypes, values. It would use the standard client protocol to return the table. Use the same serialization that mysqldump uses for dynamic columns. Give up and impelment a new protocol, e.g. MongoDB's BSON, or Google's Protocol Buffers. I like the 2. best. 1. requires me to write an SQL parser. 3. Requires standardizing (and probably versioning) the internal blob encoding. 4. is radical. 2 uses current protocols and is easy to live with. Perhaps: > SELECT COLUMN_GET_ALL(`specification`) FROM `product`; +--------------+--------------+------------+ | Name | Datatype | Value | +--------------+--------------+------------+ | category | CHAR | Transistor | | description | CHAR | TO-91 | | manufacturer | CHAR | Fairchild | | price | BLOB | NULL | | price.unit | DECIMAL(9,5) | 0.03315 | | price.100 | DECIMAL(9,5) | 2.45000 | +--------------+--------------+------------+

            People

              sanja Oleksandr Byelkin
              serg Sergei Golubchik
              Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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