Skip to content

Commit

Permalink
util: support 128 FastIntSet elements without allocation
Browse files Browse the repository at this point in the history
This commit increases the size of the "small set" bitmap from 64 bits
to 128 bits. The main goal is to avoid the slow path in optimizer
ColSets for more queries.

Fixes #72733.

Release note: None
  • Loading branch information
RaduBerinde committed Dec 14, 2021
1 parent 14367d7 commit be0aa93
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 151 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/opt/exec/execbuilder/testdata/explain
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ regions: <hidden>
query T
EXPLAIN (OPT, MEMO) SELECT * FROM tc JOIN t ON k=a
----
memo (optimized, ~10KB, required=[presentation: info:10])
memo (optimized, ~11KB, required=[presentation: info:10])
├── G1: (explain G2 [presentation: a:1,b:2,k:6,v:7])
│ └── [presentation: info:10]
│ ├── best: (explain G2="[presentation: a:1,b:2,k:6,v:7]" [presentation: a:1,b:2,k:6,v:7])
Expand Down Expand Up @@ -1677,7 +1677,7 @@ TABLE t
├── tableoid oid [hidden] [system]
└── PRIMARY INDEX t_pkey
└── k int not null
memo (optimized, ~10KB, required=[presentation: info:10])
memo (optimized, ~11KB, required=[presentation: info:10])
├── G1: (explain G2 [presentation: a:1,b:2,k:6,v:7])
│ └── [presentation: info:10]
│ ├── best: (explain G2="[presentation: a:1,b:2,k:6,v:7]" [presentation: a:1,b:2,k:6,v:7])
Expand Down
18 changes: 9 additions & 9 deletions pkg/sql/opt/memo/testdata/memo
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ WHERE a.y>1 AND a.x::string=b.x
ORDER BY y
LIMIT 10
----
memo (optimized, ~20KB, required=[presentation: y:2,x:5,c:10] [ordering: +2])
memo (optimized, ~23KB, required=[presentation: y:2,x:5,c:10] [ordering: +2])
├── G1: (project G2 G3 y x)
│ ├── [presentation: y:2,x:5,c:10] [ordering: +2]
│ │ ├── best: (project G2="[ordering: +2]" G3 y x)
Expand Down Expand Up @@ -203,7 +203,7 @@ SELECT 1 AS a, 1+z AS b, left(x, 10)::TIMESTAMP AS c, left(x, 10)::TIMESTAMPTZ A
FROM b
WHERE z=1 AND concat(x, 'foo', x)=concat(x, 'foo', x)
----
memo (optimized, ~6KB, required=[presentation: a:5,b:6,c:7,d:8])
memo (optimized, ~7KB, required=[presentation: a:5,b:6,c:7,d:8])
├── G1: (project G2 G3)
│ └── [presentation: a:5,b:6,c:7,d:8]
│ ├── best: (project G2 G3)
Expand Down Expand Up @@ -238,7 +238,7 @@ memo (optimized, ~6KB, required=[presentation: a:5,b:6,c:7,d:8])
memo
SELECT x FROM a WHERE x = 1 AND x+y = 1
----
memo (optimized, ~7KB, required=[presentation: x:1])
memo (optimized, ~8KB, required=[presentation: x:1])
├── G1: (project G2 G3 x)
│ └── [presentation: x:1]
│ ├── best: (project G2 G3 x)
Expand Down Expand Up @@ -268,7 +268,7 @@ memo (optimized, ~7KB, required=[presentation: x:1])
memo
SELECT x, y FROM a UNION SELECT x+1, y+1 FROM a
----
memo (optimized, ~7KB, required=[presentation: x:11,y:12])
memo (optimized, ~8KB, required=[presentation: x:11,y:12])
├── G1: (union G2 G3) (union G2 G3 ordering=+11,+12)
│ └── [presentation: x:11,y:12]
│ ├── best: (union G2 G3)
Expand Down Expand Up @@ -301,7 +301,7 @@ memo (optimized, ~7KB, required=[presentation: x:11,y:12])
memo
SELECT array_agg(x) FROM (SELECT * FROM a)
----
memo (optimized, ~4KB, required=[presentation: array_agg:5])
memo (optimized, ~5KB, required=[presentation: array_agg:5])
├── G1: (scalar-group-by G2 G3 cols=())
│ └── [presentation: array_agg:5]
│ ├── best: (scalar-group-by G2 G3 cols=())
Expand All @@ -317,7 +317,7 @@ memo (optimized, ~4KB, required=[presentation: array_agg:5])
memo
SELECT array_agg(x) FROM (SELECT * FROM a) GROUP BY y
----
memo (optimized, ~4KB, required=[presentation: array_agg:5])
memo (optimized, ~5KB, required=[presentation: array_agg:5])
├── G1: (project G2 G3 array_agg)
│ └── [presentation: array_agg:5]
│ ├── best: (project G2 G3 array_agg)
Expand All @@ -338,7 +338,7 @@ memo (optimized, ~4KB, required=[presentation: array_agg:5])
memo
SELECT array_agg(x) FROM (SELECT * FROM a ORDER BY y)
----
memo (optimized, ~3KB, required=[presentation: array_agg:5])
memo (optimized, ~4KB, required=[presentation: array_agg:5])
├── G1: (scalar-group-by G2 G3 cols=(),ordering=+2)
│ └── [presentation: array_agg:5]
│ ├── best: (scalar-group-by G2="[ordering: +2]" G3 cols=(),ordering=+2)
Expand All @@ -357,7 +357,7 @@ memo (optimized, ~3KB, required=[presentation: array_agg:5])
memo
SELECT DISTINCT info FROM [EXPLAIN SELECT 123 AS k]
----
memo (optimized, ~7KB, required=[presentation: info:3])
memo (optimized, ~9KB, required=[presentation: info:3])
├── G1: (distinct-on G2 G3 cols=(3))
│ └── [presentation: info:3]
│ ├── best: (distinct-on G2 G3 cols=(3))
Expand Down Expand Up @@ -385,7 +385,7 @@ memo (optimized, ~7KB, required=[presentation: info:3])
memo
SELECT DISTINCT tag FROM [SHOW TRACE FOR SESSION]
----
memo (optimized, ~6KB, required=[presentation: tag:11])
memo (optimized, ~7KB, required=[presentation: tag:11])
├── G1: (distinct-on G2 G3 cols=(11))
│ └── [presentation: tag:11]
│ ├── best: (distinct-on G2 G3 cols=(11))
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/opt/memo/testdata/stats/inverted-geo
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ project
memo
SELECT i FROM t WHERE st_intersects('LINESTRING(0.5 0.5, 0.7 0.7)', g) ORDER BY i LIMIT 1
----
memo (optimized, ~11KB, required=[presentation: i:1])
memo (optimized, ~13KB, required=[presentation: i:1])
├── G1: (project G2 G3 i)
│ └── [presentation: i:1]
│ ├── best: (project G2 G3 i)
Expand Down Expand Up @@ -195,7 +195,7 @@ project
memo
SELECT i FROM t WHERE st_intersects('LINESTRING(100 100, 150 150)', g) ORDER BY i LIMIT 1
----
memo (optimized, ~11KB, required=[presentation: i:1])
memo (optimized, ~13KB, required=[presentation: i:1])
├── G1: (project G2 G3 i)
│ └── [presentation: i:1]
│ ├── best: (project G2 G3 i)
Expand Down Expand Up @@ -303,7 +303,7 @@ select
memo
SELECT * FROM t WHERE g IS NULL OR st_intersects('LINESTRING(100 100, 150 150)', g)
----
memo (optimized, ~4KB, required=[presentation: i:1,g:2])
memo (optimized, ~5KB, required=[presentation: i:1,g:2])
├── G1: (select G2 G3)
│ └── [presentation: i:1,g:2]
│ ├── best: (select G2 G3)
Expand Down
16 changes: 8 additions & 8 deletions pkg/sql/opt/xform/testdata/physprops/ordering
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ project
memo
SELECT y, x-1 AS z FROM a WHERE x>y ORDER BY x, y DESC
----
memo (optimized, ~5KB, required=[presentation: y:2,z:7] [ordering: +1,-2])
memo (optimized, ~6KB, required=[presentation: y:2,z:7] [ordering: +1,-2])
├── G1: (project G2 G3 x y)
│ ├── [presentation: y:2,z:7] [ordering: +1,-2]
│ │ ├── best: (project G2="[ordering: +1,-2]" G3 x y)
Expand Down Expand Up @@ -355,7 +355,7 @@ sort
memo
SELECT y, z FROM a WHERE x>y ORDER BY y
----
memo (optimized, ~5KB, required=[presentation: y:2,z:3] [ordering: +2])
memo (optimized, ~6KB, required=[presentation: y:2,z:3] [ordering: +2])
├── G1: (project G2 G3 y z)
│ ├── [presentation: y:2,z:3] [ordering: +2]
│ │ ├── best: (sort G1)
Expand Down Expand Up @@ -686,7 +686,7 @@ memo (optimized, ~3KB, required=[presentation: info:7])
memo
SELECT y FROM a WITH ORDINALITY ORDER BY ordinality
----
memo (optimized, ~4KB, required=[presentation: y:2] [ordering: +7])
memo (optimized, ~5KB, required=[presentation: y:2] [ordering: +7])
├── G1: (ordinality G2)
│ ├── [presentation: y:2] [ordering: +7]
│ │ ├── best: (ordinality G2)
Expand All @@ -702,7 +702,7 @@ memo (optimized, ~4KB, required=[presentation: y:2] [ordering: +7])
memo
SELECT y FROM a WITH ORDINALITY ORDER BY -ordinality
----
memo (optimized, ~5KB, required=[presentation: y:2] [ordering: +8])
memo (optimized, ~6KB, required=[presentation: y:2] [ordering: +8])
├── G1: (project G2 G3 y)
│ ├── [presentation: y:2] [ordering: +8]
│ │ ├── best: (sort G1)
Expand All @@ -725,7 +725,7 @@ memo (optimized, ~5KB, required=[presentation: y:2] [ordering: +8])
memo
SELECT y FROM a WITH ORDINALITY ORDER BY ordinality, x
----
memo (optimized, ~6KB, required=[presentation: y:2] [ordering: +7])
memo (optimized, ~7KB, required=[presentation: y:2] [ordering: +7])
├── G1: (ordinality G2)
│ ├── [presentation: y:2] [ordering: +7]
│ │ ├── best: (ordinality G2)
Expand All @@ -741,7 +741,7 @@ memo (optimized, ~6KB, required=[presentation: y:2] [ordering: +7])
memo
SELECT y FROM (SELECT * FROM a ORDER BY y) WITH ORDINALITY ORDER BY y, ordinality
----
memo (optimized, ~5KB, required=[presentation: y:2] [ordering: +2,+7])
memo (optimized, ~6KB, required=[presentation: y:2] [ordering: +2,+7])
├── G1: (ordinality G2 ordering=+2)
│ ├── [presentation: y:2] [ordering: +2,+7]
│ │ ├── best: (ordinality G2="[ordering: +2]" ordering=+2)
Expand All @@ -760,7 +760,7 @@ memo (optimized, ~5KB, required=[presentation: y:2] [ordering: +2,+7])
memo
SELECT y FROM (SELECT * FROM a ORDER BY y) WITH ORDINALITY ORDER BY ordinality, y
----
memo (optimized, ~5KB, required=[presentation: y:2] [ordering: +7])
memo (optimized, ~6KB, required=[presentation: y:2] [ordering: +7])
├── G1: (ordinality G2 ordering=+2)
│ ├── [presentation: y:2] [ordering: +7]
│ │ ├── best: (ordinality G2="[ordering: +2]" ordering=+2)
Expand All @@ -779,7 +779,7 @@ memo (optimized, ~5KB, required=[presentation: y:2] [ordering: +7])
memo
SELECT y FROM a WITH ORDINALITY ORDER BY ordinality DESC
----
memo (optimized, ~4KB, required=[presentation: y:2] [ordering: -7])
memo (optimized, ~5KB, required=[presentation: y:2] [ordering: -7])
├── G1: (ordinality G2)
│ ├── [presentation: y:2] [ordering: -7]
│ │ ├── best: (sort G1)
Expand Down
Loading

0 comments on commit be0aa93

Please sign in to comment.