Skip to content

[Subtask]: Master Index Benchmark + Optimization #14876

Closed

Description

@arjunsk

Parent Issue

#14379

Detail of Subtask

Benchmark master index on 100-column table.

  • Without any index
  • With a secondary index on all the 100 string columns
  • With master index

Describe implementation you've considered

No response

Additional information

No response

Activity

  1. self-assigned this
    on Mar 8, 2024
  2. arjunsk commented on Mar 9, 2024

    @arjunsk
    ContributorAuthor

    STEPS

    1. Generate 100 column table with 10,000 rows using insert.py
      a.sql.zip

    2. Generate query and result dataset using query_gen.py

    query_strings.csv
    query_results.csv

    1. Run the query_qps.py code to validate the query and result against 3 scenarios
    • without index
    • with 100 secondary index
    • with a master index

    TEST RESULT

    # Type Insert duration (10_000 rows) Query QPS (1_000 queries) Query Plan
    1 Without Index 7.2sec 31 plan
    2 With 99 Secondary Index 48sec 28 plan
    3 With 1 Master Index 14sec 3.4 plan

    OBSERVATION

    1. Regular Table scan on the original table seems to be faster for queries and inserts. 99 secondary index performs badly for insert as it has to insert 99 tables. Master index performs better than 99 secondary index since it has to insert into only one table.

    2. Creating 99 regular secondary index is useless. Only one of them will be used based on the current secondary index optimizer rule.

    3. Sample Query used

    SELECT tbl.a100  FROM tbl  WHERE 
    tbl.a1 BETWEEN '2' AND 'z' AND tbl.a2 BETWEEN '1' AND 'z' AND tbl.a3 BETWEEN '1' AND '{' AND tbl.a4 BETWEEN '0' AND 'z' AND tbl.a5 BETWEEN '1' AND 'y' AND tbl.a6 BETWEEN '1' AND 'z' AND tbl.a7 BETWEEN '1' AND '{' AND tbl.a8 BETWEEN '2' AND 'z' AND tbl.a9 BETWEEN '0' AND 'y' AND tbl.a10 BETWEEN '3' AND 'y' AND tbl.a11 BETWEEN '3' AND 'y' AND tbl.a12 BETWEEN '1' AND 'z' AND tbl.a13 BETWEEN '2' AND 'y' AND tbl.a14 BETWEEN '3' AND 'y' AND tbl.a15 BETWEEN '2' AND 'z' AND tbl.a16 BETWEEN '0' AND '{' AND tbl.a17 BETWEEN '1' AND '{' AND tbl.a18 BETWEEN '2' AND '{' AND tbl.a19 BETWEEN '0' AND 'z' AND tbl.a20 BETWEEN '3' AND 'z' AND tbl.a21 BETWEEN '0' AND 'z' AND tbl.a22 BETWEEN '2' AND 'y' AND tbl.a23 BETWEEN '0' AND '{' AND tbl.a24 BETWEEN '0' AND '{' AND tbl.a25 BETWEEN '1' AND '{' AND tbl.a26 BETWEEN '3' AND 'y' AND tbl.a27 BETWEEN '3' AND 'z' AND tbl.a28 BETWEEN '0' AND '{' AND tbl.a29 BETWEEN '1' AND 'z' AND tbl.a30 BETWEEN '0' AND 'y' AND tbl.a31 BETWEEN '3' AND 'y' AND tbl.a32 BETWEEN '2' AND 'y' AND tbl.a33 BETWEEN '1' AND 'y' AND tbl.a34 BETWEEN '2' AND 'y' AND tbl.a35 BETWEEN '2' AND 'y' AND tbl.a36 BETWEEN '1' AND '{' AND tbl.a37 BETWEEN '0' AND 'z' AND tbl.a38 BETWEEN '3' AND 'z' AND tbl.a39 BETWEEN '1' AND 'z' AND tbl.a40 BETWEEN '0' AND 'z' AND tbl.a41 BETWEEN '1' AND 'y' AND tbl.a42 BETWEEN '0' AND 'z' AND tbl.a43 BETWEEN '1' AND 'y' AND tbl.a44 BETWEEN '3' AND 'y' AND tbl.a45 BETWEEN '0' AND 'z' AND tbl.a46 BETWEEN '2' AND 'y' AND tbl.a47 BETWEEN '0' AND 'y' AND tbl.a48 BETWEEN '1' AND '{' AND tbl.a49 BETWEEN '3' AND 'z' AND tbl.a50 BETWEEN '0' AND 'z' AND tbl.a51 BETWEEN '3' AND 'z' AND tbl.a52 BETWEEN '3' AND 'y' AND tbl.a53 BETWEEN '3' AND 'z' AND tbl.a54 BETWEEN '2' AND 'z' AND tbl.a55 BETWEEN '1' AND '{' AND tbl.a56 BETWEEN '0' AND 'y' AND tbl.a57 BETWEEN '2' AND 'z' AND tbl.a58 BETWEEN '2' AND '{' AND tbl.a59 BETWEEN '0' AND 'z' AND tbl.a60 BETWEEN '2' AND '{' AND tbl.a61 BETWEEN '1' AND '{' AND tbl.a62 BETWEEN '1' AND 'z' AND tbl.a63 BETWEEN '1' AND 'y' AND tbl.a64 BETWEEN '0' AND '{' AND tbl.a65 BETWEEN '3' AND 'y' AND tbl.a66 BETWEEN '1' AND 'z' AND tbl.a67 BETWEEN '2' AND 'z' AND tbl.a68 BETWEEN '2' AND '{' AND tbl.a69 BETWEEN '3' AND 'z' AND tbl.a70 BETWEEN '2' AND '{' AND tbl.a71 BETWEEN '3' AND '{' AND tbl.a72 BETWEEN '2' AND 'z' AND tbl.a73 BETWEEN '1' AND '{' AND tbl.a74 BETWEEN '0' AND 'z' AND tbl.a75 BETWEEN '0' AND '{' AND tbl.a76 BETWEEN '1' AND '{' AND tbl.a77 BETWEEN '0' AND '{' AND tbl.a78 BETWEEN '1' AND 'z' AND tbl.a79 BETWEEN '0' AND '{' AND tbl.a80 BETWEEN '2' AND 'y' AND tbl.a81 BETWEEN '0' AND 'y' AND tbl.a82 BETWEEN '2' AND 'z' AND tbl.a83 BETWEEN '2' AND '{' AND tbl.a84 BETWEEN '3' AND 'z' AND tbl.a85 BETWEEN '0' AND '{' AND tbl.a86 BETWEEN '1' AND 'z' AND tbl.a87 BETWEEN '3' AND 'z' AND tbl.a88 BETWEEN '1' AND 'z' AND tbl.a89 BETWEEN '2' AND '{' AND tbl.a90 BETWEEN '2' AND 'y' AND tbl.a91 BETWEEN '0' AND 'z' AND tbl.a92 BETWEEN '1' AND '{' AND tbl.a93 BETWEEN '3' AND 'y' AND tbl.a94 BETWEEN '1' AND 'y' AND tbl.a95 BETWEEN '2' AND 'z' AND tbl.a96 BETWEEN '2' AND 'z' AND tbl.a97 BETWEEN '2' AND 'z' AND tbl.a98 BETWEEN '1' AND '{' AND tbl.a99 BETWEEN '0' AND 'z';
    
    
  3. arjunsk commented on Mar 12, 2024

    @arjunsk
    ContributorAuthor
    # Type Insert duration (10_000 rows) Query QPS (1_000 queries)
    1 Without Index 7.2sec 1437
    2 With 99 Secondary Index 48sec 322
    3 With 1 Master Index 14sec 274
    -- no index
    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a65 = 'bh49tOecxt';
    +---------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                  |
    +---------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                     |
    |   Analyze: timeConsumed=0ms waitTime=2ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=24bytes                   |
    |   ->  Table Scan on a.tbl                                                                                                                   |
    |         Analyze: timeConsumed=1ms waitTime=0ms inputRows=10000 outputRows=1 InputSize=480000bytes OutputSize=24bytes MemorySize=490024bytes |
    |         Filter Cond: (tbl.a65 = 'bh49tOecxt')                                                                                               |
    |         Block Filter Cond: (tbl.a65 = 'bh49tOecxt')                                                                                         |
    +---------------------------------------------------------------------------------------------------------------------------------------------+
    
    -- regular secondary index
    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a65 = 'bh49tOecxt';
    +---------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                        |
    +---------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                           |
    |   Analyze: timeConsumed=0ms waitTime=2ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=24bytes                         |
    |   ->  Join                                                                                                                                        |
    |         Analyze: timeConsumed=0ms waitTime=6ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=24bytes                   |
    |         Join Type: INDEX                                                                                                                          |
    |         Join Cond: (tbl.a100 = __mo_index_secondary_018e31fe-5862-7fc2-a19e-b95a35dbcc30.__mo_index_pri_col)                                      |
    |         Runtime Filter Build: #[-1,0]                                                                                                             |
    |         ->  Table Scan on a.tbl                                                                                                                   |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=48bytes OutputSize=24bytes MemorySize=74bytes             |
    |               Filter Cond: (tbl.a65 = 'bh49tOecxt')                                                                                               |
    |               Block Filter Cond: (tbl.a65 = 'bh49tOecxt')                                                                                         |
    |               Runtime Filter Probe: tbl.a100                                                                                                      |
    |         ->  Table Scan on a.__mo_index_secondary_018e31fe-5862-7fc2-a19e-b95a35dbcc30                                                             |
    |               Analyze: timeConsumed=2ms waitTime=0ms inputRows=10000 outputRows=1 InputSize=740000bytes OutputSize=24bytes MemorySize=750024bytes |
    |               Filter Cond: prefix_eq(__mo_index_secondary_018e31fe-5862-7fc2-a19e-b95a35dbcc30.__mo_index_idx_col, 'Fbh49tOecxt ')               |
    +---------------------------------------------------------------------------------------------------------------------------------------------------+
    15 rows in set (0.04 sec)
    
    
    -- master index
    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a65 = 'bh49tOecxt';
    +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                                                                                                               |
    +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                                                                                                                  |
    |   Analyze: timeConsumed=0ms waitTime=16ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=24bytes                                                                                                               |
    |   ->  Join                                                                                                                                                                                                                               |
    |         Analyze: timeConsumed=0ms waitTime=48ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=24bytes                                                                                                         |
    |         Join Type: INDEX                                                                                                                                                                                                                 |
    |         Join Cond: (tbl.a100 = #[1,0])                                                                                                                                                                                                   |
    |         Runtime Filter Build: #[-1,0]                                                                                                                                                                                                    |
    |         ->  Table Scan on a.tbl                                                                                                                                                                                                          |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=48bytes OutputSize=24bytes MemorySize=74bytes                                                                                                    |
    |               Filter Cond: (tbl.a65 = 'bh49tOecxt')                                                                                                                                                                                      |
    |               Block Filter Cond: (tbl.a65 = 'bh49tOecxt')                                                                                                                                                                                |
    |               Runtime Filter Probe: tbl.a100                                                                                                                                                                                             |
    |         ->  Project                                                                                                                                                                                                                      |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=24bytes                                                                                                    |
    |               ->  Table Scan on a.__mo_index_secondary_018e31fe-d88b-75db-89e0-3013ffea73fc                                                                                                                                              |
    |                     Analyze: timeConsumed=74ms scan_time=[total=66ms,min=5ms,max=13ms,dop=8] filter_time=[total=7ms,min=0ms,max=1ms,dop=8] waitTime=15ms inputRows=990000 outputRows=1 InputSize=75mb OutputSize=24bytes MemorySize=76mb |
    |                     Filter Cond: prefix_eq(#[0,0], 'Fa65 Fbh49tOecxt ')                                                                                                                                                                |
    +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    17 rows in set (0.02 sec)

    Test Data

    query_strings.csv

    query_results.csv

    a.sql.zip

  4. changed the title [-][Subtask]: Master Index Benchmark[/-] [+][Subtask]: Master Index Benchmark + Optimization[/+] on Mar 23, 2024
  5. added
    priority/p0
    on Mar 23, 2024
  6. arjunsk commented on May 14, 2024

    @arjunsk
    ContributorAuthor

    Params

    • 100K Inserts
    • 5K Query

    Benchmark

    No Index With secondary index With master index
    Insert (seconds) 72 404 192
    Query (QPS) 249 671 820

    Query Plan

    • No Index
    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a50 = '1jeNbXYTKZ';
    +--------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                           |
    +--------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                              |
    |   Analyze: timeConsumed=0ms waitTime=2ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes             |
    |   ->  Table Scan on a.tbl                                                                                                            |
    |         Analyze: timeConsumed=2ms waitTime=0ms inputRows=100000 outputRows=1 InputSize=4mb OutputSize=24bytes MemorySize=493216bytes |
    |         Filter Cond: (tbl.a50 = '1jeNbXYTKZ')                                                                                        |
    |         Block Filter Cond: (tbl.a50 = '1jeNbXYTKZ')                                                                                  |
    +--------------------------------------------------------------------------------------------------------------------------------------+
    6 rows in set (0.01 sec)
    
    • Secondary Index
    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a50 = '1jeNbXYTKZ';
    +--------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                       |
    +--------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                          |
    |   Analyze: timeConsumed=0ms waitTime=5ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                         |
    |   ->  Join                                                                                                                                       |
    |         Analyze: timeConsumed=0ms waitTime=16ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                  |
    |         Join Type: INDEX                                                                                                                         |
    |         Join Cond: (tbl.a100 = __mo_index_secondary_018f75e2-bd40-7de6-a550-6392d3f4fc65.__mo_index_pri_col)                                     |
    |         Runtime Filter Build: #[-1,0]                                                                                                            |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                     |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=48bytes OutputSize=24bytes MemorySize=50bytes            |
    |               Filter Cond: (tbl.a50 = '1jeNbXYTKZ')                                                                                              |
    |               Block Filter Cond: (tbl.a50 = '1jeNbXYTKZ')                                                                                        |
    |               Runtime Filter Probe: tbl.a100                                                                                                     |
    |         ->  Table Scan on a.__mo_index_secondary_018f75e2-bd40-7de6-a550-6392d3f4fc65 [ForceOneCN]                                               |
    |               Analyze: timeConsumed=5ms waitTime=0ms inputRows=8193 outputRows=1 InputSize=606282bytes OutputSize=24bytes MemorySize=614401bytes |
    |               Filter Cond: prefix_eq(__mo_index_secondary_018f75e2-bd40-7de6-a550-6392d3f4fc65.__mo_index_idx_col, 'F1jeNbXYTKZ ')              |
    |               Block Filter Cond: prefix_eq(__mo_index_secondary_018f75e2-bd40-7de6-a550-6392d3f4fc65.__mo_index_idx_col, 'F1jeNbXYTKZ ')        |
    +--------------------------------------------------------------------------------------------------------------------------------------------------+
    16 rows in set (0.01 sec)
    
    
    • Master Index
    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a50 = '1jeNbXYTKZ';
    +---------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                        |
    +---------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                           |
    |   Analyze: timeConsumed=0ms waitTime=21ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                         |
    |   ->  Join                                                                                                                                        |
    |         Analyze: timeConsumed=0ms waitTime=63ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                   |
    |         Join Type: INDEX                                                                                                                          |
    |         Join Cond: (tbl.a100 = #[1,0])                                                                                                            |
    |         Runtime Filter Build: #[-1,0]                                                                                                             |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                      |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=48bytes OutputSize=24bytes MemorySize=50bytes             |
    |               Filter Cond: (tbl.a50 = '1jeNbXYTKZ')                                                                                               |
    |               Block Filter Cond: (tbl.a50 = '1jeNbXYTKZ')                                                                                         |
    |               Runtime Filter Probe: tbl.a100                                                                                                      |
    |         ->  Project                                                                                                                               |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes              |
    |               ->  Table Scan on a.__mo_index_secondary_018f75f3-d2b0-765c-b234-e1eff69879dc [ForceOneCN]                                          |
    |                     Analyze: timeConsumed=20ms waitTime=0ms inputRows=106496 outputRows=1 InputSize=8mb OutputSize=24bytes MemorySize=753664bytes |
    |                     Filter Cond: prefix_eq(#[0,0], 'F49 F1jeNbXYTKZ ')                                                                          |
    |                     Block Filter Cond: prefix_eq(#[0,0], 'F49 F1jeNbXYTKZ ')                                                                    |
    +---------------------------------------------------------------------------------------------------------------------------------------------------+
    18 rows in set (0.03 sec)
    
    
  7. added this to the Backlog milestone on May 27, 2024
  8. arjunsk commented on Jun 3, 2024

    @arjunsk
    ContributorAuthor

    2 Filters

    100 Secondary Index (1603 QPS)

    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a86 = 'e03PlQh6xA' AND tbl.a98 = '2xTGlIbHX9';
    +-------------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                            |
    +-------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                               |
    |   Analyze: timeConsumed=0ms waitTime=0ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                              |
    |   ->  Join                                                                                                                                            |
    |         Analyze: timeConsumed=0ms waitTime=1ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                        |
    |         Join Type: INDEX                                                                                                                              |
    |         Join Cond: (tbl.a100 = __mo_index_secondary_018fdfe9-e5af-79d3-abad-05de29150829.__mo_index_pri_col)                                          |
    |         Runtime Filter Build: #[-1,0]                                                                                                                 |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                          |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=2 inputRows=2 outputRows=2 InputSize=144bytes OutputSize=48bytes MemorySize=78bytes  |
    |               Filter Cond: (tbl.a86 = 'e03PlQh6xA'), (tbl.a98 = '2xTGlIbHX9')                                                                         |
    |               Block Filter Cond: (tbl.a86 = 'e03PlQh6xA'), (tbl.a98 = '2xTGlIbHX9')                                                                   |
    |               Runtime Filter Probe: tbl.a100                                                                                                          |
    |         ->  Table Scan on a.__mo_index_secondary_018fdfe9-e5af-79d3-abad-05de29150829 [ForceOneCN]                                                    |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=1 inputRows=2 outputRows=2 InputSize=122bytes OutputSize=48bytes MemorySize=124bytes |
    |               Filter Cond: prefix_eq(__mo_index_secondary_018fdfe9-e5af-79d3-abad-05de29150829.__mo_index_idx_col, 'Fe03PlQh6xA ')                   |
    |               Block Filter Cond: prefix_eq(__mo_index_secondary_018fdfe9-e5af-79d3-abad-05de29150829.__mo_index_idx_col, 'Fe03PlQh6xA ')             |
    +-------------------------------------------------------------------------------------------------------------------------------------------------------+

    One Master Index - One Column Used (973 QPS)

    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a86 = 'e03PlQh6xA' AND tbl.a98 = '2xTGlIbHX9';
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                                    |
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                                       |
    |   Analyze: timeConsumed=0ms waitTime=4ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                                      |
    |   ->  Join                                                                                                                                                    |
    |         Analyze: timeConsumed=0ms waitTime=11ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                               |
    |         Join Type: INDEX                                                                                                                                      |
    |         Join Cond: (tbl.a100 = #[1,0])                                                                                                                        |
    |         Runtime Filter Build: #[-1,0]                                                                                                                         |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                                  |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=2 inputRows=2 outputRows=2 InputSize=144bytes OutputSize=48bytes MemorySize=78bytes          |
    |               Filter Cond: (tbl.a86 = 'e03PlQh6xA'), (tbl.a98 = '2xTGlIbHX9')                                                                                 |
    |               Block Filter Cond: (tbl.a86 = 'e03PlQh6xA'), (tbl.a98 = '2xTGlIbHX9')                                                                           |
    |               Runtime Filter Probe: tbl.a100                                                                                                                  |
    |         ->  Project                                                                                                                                           |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                          |
    |               ->  Table Scan on a.__mo_index_secondary_018fdfec-4a14-7ce4-910e-bf0717eb823c [ForceOneCN]                                                      |
    |                     Analyze: timeConsumed=2ms waitTime=0ms inputBlocks=7 inputRows=57344 outputRows=2 InputSize=4mb OutputSize=48bytes MemorySize=704481bytes |
    |                     Filter Cond: prefix_eq(#[0,0], 'F85 Fe03PlQh6xA ')                                                                                      |
    |                     Block Filter Cond: prefix_eq(#[0,0], 'F85 Fe03PlQh6xA ')                                                                                |
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------+
    18 rows in set (0.01 sec)

    One Master Index - All Column used (561 QPS)

    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                                                                                |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                                                                                   |
    |   Analyze: timeConsumed=0ms waitTime=3ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                                                                                  |
    |   ->  Join                                                                                                                                                                                                |
    |         Analyze: timeConsumed=0ms waitTime=10ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                                                                           |
    |         Join Type: INDEX                                                                                                                                                                                  |
    |         Join Cond: (tbl.a100 = #[1,0])                                                                                                                                                                    |
    |         Runtime Filter Build: #[-1,0]                                                                                                                                                                     |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                                                                              |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=2 inputRows=2 outputRows=2 InputSize=144bytes OutputSize=48bytes MemorySize=78bytes                                                      |
    |               Filter Cond: (tbl.a86 = 'e03PlQh6xA'), (tbl.a98 = '2xTGlIbHX9')                                                                                                                             |
    |               Block Filter Cond: (tbl.a86 = 'e03PlQh6xA'), (tbl.a98 = '2xTGlIbHX9')                                                                                                                       |
    |               Runtime Filter Probe: tbl.a100                                                                                                                                                              |
    |         ->  Join                                                                                                                                                                                          |
    |               Analyze: timeConsumed=0ms probe_time=[total=0ms,min=0ms,max=0ms,dop=10] build_time=[0ms] waitTime=42ms inputRows=4 outputRows=2 InputSize=96bytes OutputSize=48bytes MemorySize=361211bytes |
    |               Join Type: INNER                                                                                                                                                                            |
    |               Join Cond: (#[0,0] = #[1,0])                                                                                                                                                                |
    |               ->  Project                                                                                                                                                                                 |
    |                     Analyze: timeConsumed=0ms waitTime=0ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                                                                |
    |                     ->  Table Scan on a.__mo_index_secondary_018fdfff-422c-7ec1-9b3a-bfacac2996db [ForceOneCN]                                                                                            |
    |                           Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=2 inputRows=16384 outputRows=2 InputSize=1mb OutputSize=48bytes MemorySize=663521bytes                                       |
    |                           Filter Cond: prefix_eq(#[0,0], 'F97 F2xTGlIbHX9 ')                                                                                                                            |
    |                           Block Filter Cond: prefix_eq(#[0,0], 'F97 F2xTGlIbHX9 ')                                                                                                                      |
    |               ->  Project                                                                                                                                                                                 |
    |                     Analyze: timeConsumed=0ms waitTime=0ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                                                                |
    |                     ->  Table Scan on a.__mo_index_secondary_018fdfff-422c-7ec1-9b3a-bfacac2996db [ForceOneCN]                                                                                            |
    |                           Analyze: timeConsumed=2ms waitTime=0ms inputBlocks=7 inputRows=57344 outputRows=2 InputSize=4mb OutputSize=48bytes MemorySize=704481bytes                                       |
    |                           Filter Cond: prefix_eq(#[0,0], 'F85 Fe03PlQh6xA ')                                                                                                                            |
    |                           Block Filter Cond: prefix_eq(#[0,0], 'F85 Fe03PlQh6xA ')                                                                                                                      |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    28 rows in set (0.02 sec)
    

    No Index (583 QPS)

    +-----------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                          |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                             |
    |   Analyze: timeConsumed=0ms waitTime=0ms inputRows=2 outputRows=2 InputSize=48bytes OutputSize=48bytes MemorySize=0bytes                            |
    |   ->  Table Scan on a.tbl                                                                                                                           |
    |         Analyze: timeConsumed=5ms waitTime=0ms inputBlocks=14 inputRows=100001 outputRows=2 InputSize=6mb OutputSize=48bytes MemorySize=689827bytes |
    |         Filter Cond: (tbl.a86 = 'e03PlQh6xA'), (tbl.a98 = '2xTGlIbHX9')                                                                             |
    |         Block Filter Cond: (tbl.a86 = 'e03PlQh6xA'), (tbl.a98 = '2xTGlIbHX9')                                                                       |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------+
    6 rows in set (0.01 sec)
  9. arjunsk commented on Jun 4, 2024

    @arjunsk
    ContributorAuthor

    1 Filter

    Regular Secondary Index (2697)

    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a10 = 'lTqGi6wVtq';
    +-----------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                          |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                             |
    |   Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                            |
    |   ->  Join                                                                                                                                          |
    |         Analyze: timeConsumed=0ms waitTime=1ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                      |
    |         Join Type: INDEX                                                                                                                            |
    |         Join Cond: (tbl.a100 = __mo_index_secondary_018fe489-73e8-775e-8f7c-a2ef093413cf.__mo_index_pri_col)                                        |
    |         Runtime Filter Build: #[-1,0]                                                                                                               |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                        |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=1 inputRows=1 outputRows=1 InputSize=48bytes OutputSize=24bytes MemorySize=50bytes |
    |               Filter Cond: (tbl.a10 = 'lTqGi6wVtq')                                                                                                 |
    |               Block Filter Cond: (tbl.a10 = 'lTqGi6wVtq')                                                                                           |
    |               Runtime Filter Probe: tbl.a100                                                                                                        |
    |         ->  Table Scan on a.__mo_index_secondary_018fe489-73e8-775e-8f7c-a2ef093413cf [ForceOneCN]                                                  |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=1 inputRows=1 outputRows=1 InputSize=74bytes OutputSize=24bytes MemorySize=75bytes |
    |               Filter Cond: prefix_eq(__mo_index_secondary_018fe489-73e8-775e-8f7c-a2ef093413cf.__mo_index_idx_col, 'FlTqGi6wVtq ')                 |
    |               Block Filter Cond: prefix_eq(__mo_index_secondary_018fe489-73e8-775e-8f7c-a2ef093413cf.__mo_index_idx_col, 'FlTqGi6wVtq ')           |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------+
    16 rows in set (0.00 sec)
    

    Master Index (900)

    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a10 = 'lTqGi6wVtq';
    +---------------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                              |
    +---------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                                 |
    |   Analyze: timeConsumed=0ms waitTime=5ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                                |
    |   ->  Join                                                                                                                                              |
    |         Analyze: timeConsumed=0ms waitTime=14ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                         |
    |         Join Type: INDEX                                                                                                                                |
    |         Join Cond: (tbl.a100 = #[1,0])                                                                                                                  |
    |         Runtime Filter Build: #[-1,0]                                                                                                                   |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                            |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=1 inputRows=1 outputRows=1 InputSize=48bytes OutputSize=24bytes MemorySize=50bytes     |
    |               Filter Cond: (tbl.a10 = 'lTqGi6wVtq')                                                                                                     |
    |               Block Filter Cond: (tbl.a10 = 'lTqGi6wVtq')                                                                                               |
    |               Runtime Filter Probe: tbl.a100                                                                                                            |
    |         ->  Table Scan on a.__mo_index_secondary_018fe49a-3b2d-7868-9d7c-f10a9034128f [ForceOneCN]                                                      |
    |               Analyze: timeConsumed=3ms waitTime=0ms inputBlocks=7 inputRows=57344 outputRows=1 InputSize=4mb OutputSize=24bytes MemorySize=704512bytes |
    |               Filter Cond: prefix_eq(#[0,0], 'F9 FlTqGi6wVtq ')                                                                                       |
    |               Block Filter Cond: prefix_eq(#[0,0], 'F9 FlTqGi6wVtq ')                                                                                 |
    +---------------------------------------------------------------------------------------------------------------------------------------------------------+
    16 rows in set (0.01 sec)
    

    Reason for QPS difference:
    image

    No Index (500)

    +------------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                           |
    +------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                              |
    |   Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                             |
    |   ->  Table Scan on a.tbl                                                                                                                            |
    |         Analyze: timeConsumed=11ms waitTime=0ms inputBlocks=13 inputRows=100000 outputRows=1 InputSize=4mb OutputSize=24bytes MemorySize=493216bytes |
    |         Filter Cond: (tbl.a10 = 'lTqGi6wVtq')                                                                                                        |
    |         Block Filter Cond: (tbl.a10 = 'lTqGi6wVtq')                                                                                                  |
    +------------------------------------------------------------------------------------------------------------------------------------------------------+
    6 rows in set (0.01 sec)
    
  10. arjunsk commented on Jun 5, 2024

    @arjunsk
    ContributorAuthor

    Issue with Runtime Filter on Inner Join

    Current (with Project)

    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a53 = 's8JMmtdSUc' AND tbl.a52 = 'USl52A9PtO';
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                                                                                |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                                                                                   |
    |   Analyze: timeConsumed=0ms waitTime=3ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                                                                                  |
    |   ->  Join                                                                                                                                                                                                |
    |         Analyze: timeConsumed=0ms waitTime=8ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                                                                            |
    |         Join Type: INDEX                                                                                                                                                                                  |
    |         Join Cond: (tbl.a100 = #[1,0])                                                                                                                                                                    |
    |         Runtime Filter Build: #[-1,0]                                                                                                                                                                     |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                                                                              |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=1 inputRows=1 outputRows=1 InputSize=72bytes OutputSize=24bytes MemorySize=75bytes                                                       |
    |               Filter Cond: (tbl.a53 = 's8JMmtdSUc'), (tbl.a52 = 'USl52A9PtO')                                                                                                                             |
    |               Block Filter Cond: (tbl.a53 = 's8JMmtdSUc'), (tbl.a52 = 'USl52A9PtO')                                                                                                                       |
    |               Runtime Filter Probe: tbl.a100                                                                                                                                                              |
    |         ->  Join                                                                                                                                                                                          |
    |               Analyze: timeConsumed=0ms probe_time=[total=0ms,min=0ms,max=0ms,dop=10] build_time=[0ms] waitTime=34ms inputRows=2 outputRows=1 InputSize=48bytes OutputSize=24bytes MemorySize=361187bytes |
    |               Join Type: INNER                                                                                                                                                                            |
    |               Join Cond: (#[0,0] = #[1,0])                                                                                                                                                                |
    |               ->  Project                                                                                                                                                                                 |
    |                     Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                                                                |
    |                     ->  Table Scan on a.__mo_index_secondary_018fe4e8-90f7-71fb-9733-0bba94611e51 [ForceOneCN]                                                                                            |
    |                           Analyze: timeConsumed=1ms waitTime=0ms inputBlocks=5 inputRows=40960 outputRows=1 InputSize=3mb OutputSize=24bytes MemorySize=688128bytes                                       |
    |                           Filter Cond: prefix_eq(#[0,0], 'F51 FUSl52A9PtO ')                                                                                                                            |
    |                           Block Filter Cond: prefix_eq(#[0,0], 'F51 FUSl52A9PtO ')                                                                                                                      |
    |               ->  Project                                                                                                                                                                                 |
    |                     Analyze: timeConsumed=0ms waitTime=0ms inputRows=1 outputRows=1 InputSize=24bytes OutputSize=24bytes MemorySize=0bytes                                                                |
    |                     ->  Table Scan on a.__mo_index_secondary_018fe4e8-90f7-71fb-9733-0bba94611e51 [ForceOneCN]                                                                                            |
    |                           Analyze: timeConsumed=1ms waitTime=0ms inputBlocks=5 inputRows=40960 outputRows=1 InputSize=3mb OutputSize=24bytes MemorySize=688128bytes                                       |
    |                           Filter Cond: prefix_eq(#[0,0], 'F52 Fs8JMmtdSUc ')                                                                                                                            |
    |                           Block Filter Cond: prefix_eq(#[0,0], 'F52 Fs8JMmtdSUc ')                                                                                                                      |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    28 rows in set (0.01 sec)
    

    New (without Project)

    Change List: https://github.com/arjunsk/matrixone/pull/92

    mysql> explain analyze SELECT tbl.a100  FROM tbl  WHERE tbl.a53 = 's8JMmtdSUc' AND tbl.a52 = 'USl52A9PtO';
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | QUERY PLAN                                                                                                                                                    |
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Project                                                                                                                                                       |
    |   Analyze: timeConsumed=0ms waitTime=3ms inputRows=0 outputRows=0 InputSize=0bytes OutputSize=0bytes MemorySize=0bytes                                        |
    |   ->  Join                                                                                                                                                    |
    |         Analyze: timeConsumed=0ms waitTime=10ms inputRows=0 outputRows=0 InputSize=0bytes OutputSize=0bytes MemorySize=0bytes                                 |
    |         Join Type: INDEX                                                                                                                                      |
    |         Join Cond: (tbl.a100 = #[1,0])                                                                                                                        |
    |         Runtime Filter Build: #[-1,0]                                                                                                                         |
    |         ->  Table Scan on a.tbl [ForceOneCN]                                                                                                                  |
    |               Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=0 inputRows=0 outputRows=0 InputSize=0bytes OutputSize=0bytes MemorySize=0bytes              |
    |               Filter Cond: (tbl.a53 = 's8JMmtdSUc'), (tbl.a52 = 'USl52A9PtO')                                                                                 |
    |               Block Filter Cond: (tbl.a53 = 's8JMmtdSUc'), (tbl.a52 = 'USl52A9PtO')                                                                           |
    |               Runtime Filter Probe: tbl.a100                                                                                                                  |
    |         ->  Join                                                                                                                                              |
    |               Analyze: timeConsumed=0ms waitTime=9ms inputRows=1 outputRows=0 InputSize=24bytes OutputSize=0bytes MemorySize=65690bytes                       |
    |               Join Type: INNER                                                                                                                                |
    |               Join Cond: (#[0,0] = #[1,0])                                                                                                                    |
    |               Runtime Filter Build: #[-1,0]                                                                                                                   |
    |               ->  Table Scan on a.__mo_index_secondary_018fe4e8-90f7-71fb-9733-0bba94611e51 [ForceOneCN]                                                      |
    |                     Analyze: timeConsumed=0ms waitTime=0ms inputBlocks=0 inputRows=0 outputRows=0 InputSize=0bytes OutputSize=0bytes MemorySize=0bytes        |
    |                     Filter Cond: prefix_eq(#[0,0], 'F51 FUSl52A9PtO ')                                                                                      |
    |                     Block Filter Cond: prefix_eq(#[0,0], 'F51 FUSl52A9PtO ')                                                                                |
    |                     Runtime Filter Probe: #[0,1]                                                                                                              |
    |               ->  Table Scan on a.__mo_index_secondary_018fe4e8-90f7-71fb-9733-0bba94611e51 [ForceOneCN]                                                      |
    |                     Analyze: timeConsumed=2ms waitTime=0ms inputBlocks=5 inputRows=40960 outputRows=1 InputSize=3mb OutputSize=24bytes MemorySize=688128bytes |
    |                     Filter Cond: prefix_eq(#[0,0], 'F52 Fs8JMmtdSUc ')                                                                                      |
    |                     Block Filter Cond: prefix_eq(#[0,0], 'F52 Fs8JMmtdSUc ')                                                                                |
    +---------------------------------------------------------------------------------------------------------------------------------------------------------------+
    26 rows in set (0.00 sec)

    Issue with New Approach

    image

    Due to the new runtime filter, the input rows = 0.

    However, both the table scans should return 1 row.

    mysql> select * from `__mo_index_secondary_018fe4e8-90f7-71fb-9733-0bba94611e51` where prefix_eq(`__mo_index_idx_col`, serial_full('51', 'USl52A9PtO'));
    +---------------------------------+--------------------+
    | __mo_index_idx_col              | __mo_index_pri_col |
    +---------------------------------+--------------------+
    | F51 FUSl52A9PtO F000kcagPeu  | 000kcagPeu         |
    +---------------------------------+--------------------+
    1 row in set (0.00 sec)
    
    mysql> 
    mysql> select * from `__mo_index_secondary_018fe4e8-90f7-71fb-9733-0bba94611e51` where prefix_eq(`__mo_index_idx_col`, serial_full('52', 's8JMmtdSUc'));
    +---------------------------------+--------------------+
    | __mo_index_idx_col              | __mo_index_pri_col |
    +---------------------------------+--------------------+
    | F52 Fs8JMmtdSUc F000kcagPeu  | 000kcagPeu         |
    +---------------------------------+--------------------+
    1 row in set (0.00 sec)
    
    
  11. arjunsk commented on Jun 5, 2024

    @arjunsk
    ContributorAuthor

    Solved it using logic that compares column names to see if it is a master/secondary index table.

    func (builder *QueryBuilder) generateRuntimeFilters(nodeID int32) {
    	node := builder.qry.Nodes[nodeID]
    
    	for _, childID := range node.Children {
    		builder.generateRuntimeFilters(childID)
    	}
    
    	// In Master Index, INNER Joins in the query plan should not have runtime filters, as set
    	// input rows to 0, which is not expected.
    	// https://github.com/matrixorigin/matrixone/issues/14876#issuecomment-2148824892
    	if node.JoinType == plan.Node_INNER && len(node.Children) == 2 {
    
    		leftChild := builder.qry.Nodes[node.Children[0]]
    		rightChild := builder.qry.Nodes[node.Children[1]]
    
    		if leftChild.TableDef == nil || leftChild.TableDef.Cols == nil || len(leftChild.TableDef.Cols) != 2 {
    			return
    		}
    
    		if rightChild.TableDef == nil || rightChild.TableDef.Cols == nil || len(rightChild.TableDef.Cols) != 2 {
    			return
    		}
    
    		// In Master Index, both the children are from the same master index table.
    		if leftChild.TableDef.Name != rightChild.TableDef.Name {
    			return
    		}
    
    		// Check if left child is a master/secondary index table
    		leftIsSecondaryIndexOrMasterIndexHiddenTable := true
    		for _, column := range leftChild.TableDef.Cols {
    			if column.Name == catalog.MasterIndexTablePrimaryColName {
    				continue
    			}
    			if column.Name == catalog.MasterIndexTableIndexColName {
    				continue
    			}
    			leftIsSecondaryIndexOrMasterIndexHiddenTable = false
    		}
    
    		// Check if right child is a master/secondary index table
    		rightIsSecondaryIndexOrMasterIndexHiddenTable := true
    		for _, column := range rightChild.TableDef.Cols {
    			if column.Name == catalog.MasterIndexTablePrimaryColName {
    				continue
    			}
    			if column.Name == catalog.MasterIndexTableIndexColName {
    				continue
    			}
    			rightIsSecondaryIndexOrMasterIndexHiddenTable = false
    		}
    
    		if leftIsSecondaryIndexOrMasterIndexHiddenTable && rightIsSecondaryIndexOrMasterIndexHiddenTable {
    			return
    		}
    	}
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/subtaskpriority/p0

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions