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

Testing for MDEV-40777: Indexes over JSON data based on Fulltext index

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • N/A
    • Optimizer
    • None

    Description

      Contents

      Step 1: Test fulltext estimates.
      Step 2: Correctness testing
      

      Step 1: Test fulltext estimates.

      MDEV-40777 includes code to estimate how many matches fulltext index for a keyword. That code needs testing.

      Let's take this definition

      CREATE TABLE mvi_ft_estimate_test (
          id INT AUTO_INCREMENT PRIMARY KEY,
          attributes JSON,
          attr1 VARCHAR(255),
          INDEX idx_attributes ((CAST(attributes->'$.tags' AS CHAR(32) ARRAY))),
          INDEX idx_attr1 (attr1)
      );
      

      Insert, say 10M rows.

      Generate dataset like this (first idea that came to mind):

      -- de-duplicated list of names. We'll need it later on:
      create table all_names (
        name varchar(100) primary key
      );
      

      set pop190_count = (select count * from pop1980);
      for i in 1...10M do
       
        json='{"tags": []}';
        // 0.01% probability of empty document:
        if (rand() < 1/100. /100) 
          goto end;
        
        for (i=0;; i++) {
          // get a random row from pop1980 table;
          set @pk=pop190_count*rand();
          // Get the name. This way, we get popular names more often,
          // rougly according to the distribution.
          set @name= (select firstname from pop1980 where pk=@pk);
         
          // Save the name
          insert ignore into all_names values(@name);
       
          // Insert the @name into "tags" array:
          json = ... ;
          
          /*
            Not counting empty arrays, let the array have
              50% = 1 element
              25% = 2 elements
              12.5% - 4 elements 
               etc.
          */
          if (rand() > 0.5)
           break;
        }
        insert into mvi_ft_estimate_test (attributes) values (json);
      }
      

      Then, shutdown and restart the server.
      Then,

      for each row in all_names {
        $name= <the name>;
        analyze format=json
        select * 
        from t1 force index (idx_attributes) 
        where json_overlaps(attributes->'$.tags', '"$name"');
         Record rows and r_rows.
      }
      

      Then, plot rows vs r_rows.
      And distribution of rows/r_rows (we only request values that exist to no divide-by-zero questions here).

      Step 2: Correctness testing

      Test that indexed reads produce correct results.
      Construct two tables with identical content, one has an ARRAY index, another one doesn't. Try various datatypes for the ARRAY index (see the linked MDEV and/or mtr tests in the tree to see what is accepted).

      Run various queries in form

      select ... from tbl where cond ...
      

      and the cond includes JSON_CONTAINS and/or JSON_OVERLAPS predicates that the optimizer will use to do index reads through ARRAY index.
      Compare query results.

      Attachments

        1. yob1980-ddl.sql
          0.1 kB
          Sergei Petrunia
        2. yob1980-pop.sql.bz2
          4.15 MB
          Sergei Petrunia

        Issue Links

          Activity

            People

              mariadb-pavithrapandith Pavithra Pandith
              psergei Sergei Petrunia
              Votes:
              0 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.