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

Optimizer support for Multi-Valued indexes over JSON data

    XMLWordPrintable

Details

    Description

      After MDEV-25848 implements multi-value indexes, the optimizer could use those to perform efficient searches for JSON data.

      This will achieve either or both of the goals:

      Goal 1: Do index searches like in MySQL

      create index idx1 on  t1 ((cast(a->'$.arr' as unsigned array)));
      explain select * from t101 where 4 member of (a->'$.arr');
      

      Without MDEV-13594 (support for '->' syntax), an alternative would be using JSON_EXTRACT:

      create index idx1 on  t1 ((cast (json_extract(a, '$.arr') as unsigned array)));
      

      MySQL does support this also. Ultimately it depends on what MDEV-25848 implements.

      In MySQL, UNSIGNED ARRAY is not a real datatype

      The CAST ... AS UNSIGNED ARRAY syntax is only accepted in index definitions. Attempt to use it somewhere else gives this error:

      ERROR 1235 (42000): This version of MySQL doesn't yet support 'Use of CAST( .. AS .. 
      ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in 
      general expressions'
      

      Sargable conditions in MySQL

      Those are:

      • MEMBER OF
      • JSON_CONTAINS
      • JSON_OVERLAPS

      MEMBER OF syntax is MySQL-specific

      SQL Standard does define MEMBER OF but it's for MULTISET datatypes which are not related to JSON documents.
      MariaDB's Jira task for implementing MEMBER OF is MDEV-38591 (a GSoC task this year?).

      Goal 2: Support indexed searches for JSON members.

      The idea is to support searches for conditions like

      WHERE JSON_VALUE(js_column, '$.attribute_name') = 'value'
      

      where we do not require a prior index created for attribute_name.

      When/if arrow -> syntax is allowed for JSON, this will also handle

        
      WHERE column->'$.json_attr' = 'foo';
      

      Note that the -> operator MDEV-13594 has been pushed to 13.1.

      The scope of this task.

      MDEV-25848 be implemented before this task. It will add Multi-Value Index support for New Fulltext and vector indexes.
      It will NOT do anything for JSON.
      The scope of this task is everything else needed to get the above JSON use cases running.

      • Adjust CREATE TABLE to support new index definitions.
      • Produce index entries for a table row.
      • Detect relevant expressions in the WHERE clause and construct Access Methods for them
      • ...

      Attachments

        Issue Links

          Activity

            People

              ycp Yuchen Pei
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 40d
                  40d
                  Remaining:
                  Time Spent - 6h 53m Remaining Estimate - 39d 1h 7m
                  39d 1h 7m
                  Logged:
                  Time Spent - 6h 53m Remaining Estimate - 39d 1h 7m
                  6h 53m

                  Git Integration

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