Skip to content

Commit

Permalink
sql: add estimated row count to all operators in EXPLAIN
Browse files Browse the repository at this point in the history
This change adds the estimated row count to all operators in the
vanilla EXPLAIN, as long as the tables involved had statistics.

Fixes #61310.

Release justification: bug fixes and low-risk updates to new functionality

Release note (sql change): EXPLAIN now shows estimated row counts for
all operators even without VERBOSE (except when we don't have
statistics for the tables).
  • Loading branch information
RaduBerinde committed Mar 2, 2021
1 parent 9bf97ac commit c3c7d70
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ vectorized: true
│ │ spans: FULL SCAN
│ │
│ └── • scan buffer
│ estimated row count: 1
│ label: buffer 1
└── • constraint-check
Expand All @@ -673,6 +674,7 @@ vectorized: true
│ spans: FULL SCAN
└── • scan buffer
estimated row count: 1
label: buffer 1

statement ok
Expand Down
5 changes: 5 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/regional_by_row
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ vectorized: true
│ │ pred: column15 != crdb_region
│ │
│ └── • cross join
│ │ estimated row count: 3
│ │
│ ├── • values
│ │ size: 1 column, 3 rows
Expand All @@ -705,6 +706,7 @@ vectorized: true
│ │ pred: (column1 != pk) OR (column15 != crdb_region)
│ │
│ └── • cross join
│ │ estimated row count: 3
│ │
│ ├── • values
│ │ size: 1 column, 3 rows
Expand All @@ -723,6 +725,7 @@ vectorized: true
│ pred: (column1 != pk) OR (column15 != crdb_region)
└── • cross join
│ estimated row count: 3
├── • values
│ size: 1 column, 3 rows
Expand Down Expand Up @@ -831,6 +834,7 @@ vectorized: true
│ │ locking strength: for update
│ │
│ └── • render
│ │ estimated row count: 2
│ │
│ └── • values
│ size: 5 columns, 2 rows
Expand Down Expand Up @@ -1156,6 +1160,7 @@ vectorized: true
│ pred: (column1 != pk) OR (column10 != crdb_region_col)
└── • cross join
│ estimated row count: 3
├── • values
│ size: 1 column, 3 rows
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/explain_analyze_plans
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ distribution: full
vectorized: true
·
• group (scalar)
│ estimated row count: 1
└── • norows
·
Expand Down Expand Up @@ -330,6 +331,7 @@ network usage: <hidden>
└── • filter
│ cluster nodes: <hidden>
│ actual row count: 1
│ estimated row count: 1
│ filter: column2 IS NOT NULL
└── • scan buffer
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/vectorize_threshold
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ distribution: full
vectorized: false
·
• group (scalar)
│ estimated row count: 1
└── • scan
estimated row count: 100 (100% of the table)
Expand All @@ -84,6 +85,7 @@ distribution: full
vectorized: true
·
• group (scalar)
│ estimated row count: 1
└── • scan
estimated row count: 100 (100% of the table)
Expand Down Expand Up @@ -114,6 +116,7 @@ distribution: full
vectorized: true
·
• group (scalar)
│ estimated row count: 1
└── • scan
estimated row count: 100,000 (100% of the table)
Expand All @@ -132,6 +135,7 @@ distribution: full
vectorized: false
·
• group (scalar)
│ estimated row count: 1
└── • scan
estimated row count: 100,000 (100% of the table)
Expand All @@ -150,6 +154,7 @@ distribution: full
vectorized: true
·
• merge join
│ estimated row count: 100
│ equality: (a) = (a)
│ left cols are key
│ right cols are key
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/distsql_agg
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,10 @@ distribution: full
vectorized: true
·
• group (scalar)
│ estimated row count: 1
└── • filter
│ estimated row count: 1
│ filter: column2 > 3
└── • values
Expand All @@ -682,6 +684,7 @@ distribution: full
vectorized: true
·
• hash join
│ estimated row count: 2
│ equality: (column1) = (column1)
├── • values
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/distsql_union
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ distribution: full
vectorized: true
·
• union
│ estimated row count: 4
├── • values
│ size: 1 column, 2 rows
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/explain
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ distribution: local
vectorized: true
·
• group (scalar)
│ estimated row count: 1
└── • values
size: 2 columns, 2 rows
Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/fk
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ vectorized: true
│ equality cols are key
└── • filter
│ estimated row count: 1
│ filter: column2 IS NOT NULL
└── • scan buffer
Expand Down Expand Up @@ -156,6 +157,7 @@ vectorized: true
│ equality cols are key
└── • filter
│ estimated row count: 1
│ filter: (column2 IS NOT NULL) AND (column3 IS NOT NULL)
└── • scan buffer
Expand Down Expand Up @@ -204,6 +206,7 @@ vectorized: true
│ │ equality cols are key
│ │
│ └── • filter
│ │ estimated row count: 1
│ │ filter: column2 IS NOT NULL
│ │
│ └── • scan buffer
Expand All @@ -219,6 +222,7 @@ vectorized: true
│ equality cols are key
└── • filter
│ estimated row count: 1
│ filter: (column3 IS NOT NULL) AND (column4 IS NOT NULL)
└── • scan buffer
Expand Down Expand Up @@ -1210,6 +1214,7 @@ vectorized: true
└── • error if rows
└── • hash join (anti)
│ estimated row count: 2
│ equality: (column2) = (p)
│ right cols are key
Expand Down Expand Up @@ -1237,6 +1242,7 @@ vectorized: true
│ │ label: buffer 1
│ │
│ └── • render
│ │ estimated row count: 1
│ │
│ └── • scan
│ estimated row count: 1 (100% of the table)
Expand All @@ -1249,10 +1255,12 @@ vectorized: true
└── • error if rows
└── • hash join (anti)
│ estimated row count: 0
│ equality: (p_new) = (p)
│ right cols are key
├── • filter
│ │ estimated row count: 1
│ │ filter: p_new IS NOT NULL
│ │
│ └── • scan buffer
Expand All @@ -1279,6 +1287,7 @@ vectorized: true
│ │ label: buffer 1
│ │
│ └── • render
│ │ estimated row count: 1
│ │
│ └── • scan
│ estimated row count: 1 (100% of the table)
Expand All @@ -1291,10 +1300,12 @@ vectorized: true
└── • error if rows
└── • hash join (semi)
│ estimated row count: 0
│ equality: (p) = (p)
│ left cols are key
├── • except
│ │ estimated row count: 1
│ │
│ ├── • scan buffer
│ │ label: buffer 1
Expand Down Expand Up @@ -1331,10 +1342,12 @@ vectorized: true
└── • error if rows
└── • hash join (semi)
│ estimated row count: 0
│ equality: (p) = (p)
│ left cols are key
├── • scan buffer
│ estimated row count: 1
│ label: buffer 1
└── • scan
Expand Down Expand Up @@ -1374,6 +1387,7 @@ vectorized: true
│ │ label: buffer 1
│ │
│ └── • render
│ │ estimated row count: 1
│ │
│ └── • scan
│ estimated row count: 1 (100% of the table)
Expand All @@ -1386,11 +1400,13 @@ vectorized: true
└── • error if rows
└── • lookup join (anti)
│ estimated row count: 0
│ table: p@primary
│ equality: (p_new) = (p)
│ equality cols are key
└── • filter
│ estimated row count: 1
│ filter: p_new IS NOT NULL
└── • scan buffer
Expand All @@ -1412,6 +1428,7 @@ vectorized: true
│ │ label: buffer 1
│ │
│ └── • render
│ │ estimated row count: 1
│ │
│ └── • scan
│ estimated row count: 1 (100% of the table)
Expand All @@ -1424,10 +1441,12 @@ vectorized: true
└── • error if rows
└── • lookup join (semi)
│ estimated row count: 0
│ table: c@c_p_idx
│ equality: (p) = (p)
└── • except
│ estimated row count: 1
├── • scan buffer
│ label: buffer 1
Expand Down Expand Up @@ -1459,10 +1478,12 @@ vectorized: true
└── • error if rows
└── • lookup join (semi)
│ estimated row count: 0
│ table: c@c_p_idx
│ equality: (p) = (p)
└── • scan buffer
estimated row count: 1
label: buffer 1

statement ok
Expand Down Expand Up @@ -1500,8 +1521,10 @@ vectorized: true
│ │ label: buffer 1
│ │
│ └── • render
│ │ estimated row count: 10
│ │
│ └── • project set
│ │ estimated row count: 10
│ │
│ └── • emptyrow
Expand All @@ -1510,6 +1533,7 @@ vectorized: true
└── • error if rows
└── • hash join (anti)
│ estimated row count: 0
│ equality: (?column?) = (p)
│ right cols are key
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/insert
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,10 @@ vectorized: true
│ auto commit
└── • render
│ estimated row count: 1
└── • limit
│ estimated row count: 1
│ count: 1
└── • values
Expand All @@ -395,11 +397,14 @@ vectorized: true
│ auto commit
└── • render
│ estimated row count: 1
└── • limit
│ estimated row count: 1
│ count: 1
└── • sort
│ estimated row count: 2
│ order: +column2
└── • values
Expand All @@ -416,11 +421,14 @@ vectorized: true
│ auto commit
└── • render
│ estimated row count: 1
└── • limit
│ estimated row count: 1
│ count: 1
└── • sort
│ estimated row count: 2
│ order: +column2
└── • values
Expand All @@ -437,11 +445,14 @@ vectorized: true
│ auto commit
└── • render
│ estimated row count: 1
└── • limit
│ estimated row count: 1
│ count: 1
└── • sort
│ estimated row count: 2
│ order: +column2
└── • values
Expand Down
Loading

0 comments on commit c3c7d70

Please sign in to comment.