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

User-friendly syntax for dynamic columns

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      (These are the notes taken from discussion with Sergei Golubchik)

      The idea is to make syntax more user-friendly: allow "direct" access to dynamic
      columns:

      SELECT dynamic_column1, dynamic_column2 FROM table1, table2 WHERE ... 
      

      This can be made to work via a "field discovery" process, similar to a table discovery.

      • During the name resolution, for all unresolved columns the server tries to "discover" them.
      • Basically it asks all tables what type the column X has.
      • The table can simply return an error (column not found)
      • Or, if it is a dynamic column, the table can return its type
        • in a special case (that's how most NoSQL databases work) the table cannot know a column with a particular name exists in any of the rows. So it simply returns a default type, say, VARCHAR(255) or TEXT for any column X discovery request. If the column will later happen out to be numeric and it will be used in a numeric context, we use item->val_int() anyway, so there should be no number->string->number conversion.
      • The server needs to ask all participating engines. It might happen that the column will be discovered in more than one table. This is a usual "ambiguous column name" SQL error. And the workaround is as usual - the user needs to qualify the column name with a table name.
      • there might be a default implementation of dynamic columns in the base handler class. this implementation will create a shadow BLOB column and will use ADD_COLUMN/GET_COLUMN encoding to read and store the data.

      After a column is resolved, a Field object is created for it, record[0] and read_map/etc are expanded accordingly and the rest of the server code doesn't see any difference between dynamically and statically declared columns.

      DDL for tables with dynamic columns

      There are two possibilities.

      1. One can explicitly declare a table as having dynamic columns:

      CREATE TABLE t1
      ( 
         column1 INT,
         ...  -- this means "and a set of dynamic columns"
      );
      

      Or

      CREATE TABLE t1 ( ... ) DYNAMIC_COLUMNS=ON;
      

      And here's a way to specify default column type for dynamic columns (see "a special case" above)

      CREATE TABLE t1
      ( 
         column1 INT,
         ... CHAR(N)
      );
      

      2. One does not need to declare anything specially. If the engine supports dynamic columns (e.g. storage engine, based on a NoSQL database) - they are always available. If the engine does not support them - they aren't available. This does not work very well if we'll have a default implementation in the handler class.

      various concerns

      • Will row-based replication work with this?
      • increasing record buffer and bitmaps may be expensive. Is there a cheaper solution for hiding dynamic columns from the rest of the server code?
      • What to do for SELECT *?
        • variants: error. only show static columns
      • How to see all columns in a row?
        • use LIST_COLUMNS function?

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            rspadim roberto spadim added a comment -

            maybe using :: could tell parser that this field is a dynamic column field?
            select
            some_dinamic_field::column_name AS dynamic_column_name,
            some_dinamic_field::9999 as dynamic_column_number
            from some_table
            where primary_key=1

            update some_table set
            some_dinamic_field::column_name=10
            where primary_key=1

            delete from some_table
            where some_dinamic_field::column_name=20

            it's easy to understand, not?

            Show
            rspadim roberto spadim added a comment - maybe using :: could tell parser that this field is a dynamic column field? select some_dinamic_field::column_name AS dynamic_column_name, some_dinamic_field::9999 as dynamic_column_number from some_table where primary_key=1 update some_table set some_dinamic_field::column_name=10 where primary_key=1 delete from some_table where some_dinamic_field::column_name=20 it's easy to understand, not?
            Hide
            rspadim roberto spadim added a comment -

            What to do for SELECT *?
            select * from table - normal (will return column value)
            select column::* from table - return just columns from a dc (dynamic column)

            How to see all columns in a row?
            select :: from table - will return all values but column that have dynamic value (varchar,varbinary,text,blob) will be converted to dynamic values

            use LIST_COLUMNS function?
            show fields from table a => normal fields
            show fields from table a where column=xxx => dynamic fields
            show fields from field a::column => dynamic fields 'keys'

            just some ideas, may be more tools using :: or other special combination

            select column::keys from some_table where id=xxx (return key=>value)
            select column[keys] from some_table where id=xx (return key)
            select column[values] from some_table where id=xx (return values)

            i'm thinking like a php programmer (array_values, array_keys functions)

            just some ideas

            Show
            rspadim roberto spadim added a comment - What to do for SELECT *? select * from table - normal (will return column value) select column::* from table - return just columns from a dc (dynamic column) How to see all columns in a row? select :: from table - will return all values but column that have dynamic value (varchar,varbinary,text,blob) will be converted to dynamic values use LIST_COLUMNS function? show fields from table a => normal fields show fields from table a where column=xxx => dynamic fields show fields from field a::column => dynamic fields 'keys' just some ideas, may be more tools using :: or other special combination select column::keys from some_table where id=xxx (return key=>value) select column [keys] from some_table where id=xx (return key) select column [values] from some_table where id=xx (return values) i'm thinking like a php programmer (array_values, array_keys functions) just some ideas

              People

              • Assignee:
                Unassigned
                Reporter:
                psergey Sergei Petrunia
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour
                  1h