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 Nov 30, 2021
1 parent aa57c39 commit d26223c
Show file tree
Hide file tree
Showing 17 changed files with 370 additions and 268 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/logictestccl/testdata/logic_test/as_of
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ SELECT * FROM t AS OF SYSTEM TIME with_max_staleness('1ms') WHERE j = 2
query T
EXPLAIN (OPT, MEMO) SELECT * FROM t AS OF SYSTEM TIME with_max_staleness('1ms') WHERE j = 2 AND i = 1
----
memo (optimized, ~7KB, required=[presentation: info:6])
memo (optimized, ~8KB, required=[presentation: info:6])
├── G1: (explain G2 [presentation: i:1,j:2,k:3])
│ └── [presentation: info:6]
│ ├── best: (explain G2="[presentation: i:1,j:2,k:3]" [presentation: i:1,j:2,k:3])
Expand Down
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 @@ -1594,7 +1594,7 @@ regions: <hidden>
query T
EXPLAIN (OPT, MEMO) SELECT * FROM tc JOIN t ON k=a
----
memo (optimized, ~14KB, required=[presentation: info:10])
memo (optimized, ~16KB, 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 @@ -1653,7 +1653,7 @@ TABLE t
├── tableoid oid [hidden] [system]
└── PRIMARY INDEX t_pkey
└── k int not null
memo (optimized, ~14KB, required=[presentation: info:10])
memo (optimized, ~16KB, 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: 11 additions & 7 deletions pkg/sql/opt/exec/explain/plan_gist_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ func init() {
}
}

// version tracks major changes to how we encode plans or to the operator set.
// It isn't necessary to increment it when adding a single operator but if we
// remove an operator or change the operator set or decide to use a more
// gistVersion tracks major changes to how we encode plans or to the operator
// set. It isn't necessary to increment it when adding a single operator but if
// we remove an operator or change the operator set or decide to use a more
// efficient encoding version should be incremented.
var version = 1
//
// Version history:
// 1. Initial version.
// 2. FastIntSet encoding changed.
var gistVersion = 2

// PlanGist is a compact representation of a logical plan meant to be used as
// a key and log for different plans used to implement a particular query. A
Expand Down Expand Up @@ -117,7 +121,7 @@ func NewPlanGistFactory(wrappedFactory exec.Factory) *PlanGistFactory {
f := new(PlanGistFactory)
f.wrappedFactory = wrappedFactory
f.hash.Init()
f.encodeInt(version)
f.encodeInt(gistVersion)
return f
}

Expand Down Expand Up @@ -186,8 +190,8 @@ func DecodePlanGistToPlan(s string, cat cat.Catalog) (plan *Plan, retErr error)
}()

ver := f.decodeInt()
if ver != version {
return nil, errors.Errorf("unsupported old plan gist version %d", ver)
if ver != gistVersion {
return nil, errors.Errorf("unsupported gist version %d (expected %d)", ver, gistVersion)
}

for {
Expand Down
Loading

0 comments on commit d26223c

Please sign in to comment.