Skip to content

Commit

Permalink
Merge #114623
Browse files Browse the repository at this point in the history
114623: opt: reduce planning time for queries with many joins r=mgartner a=mgartner

#### opt: move slow-query benchmark schemas to SQL file

This commit moves the schemas used for slow-query benchmarks into a
separate SQL file so that the schemas can continue to grow without
making a mess of `bench_test.go`.

Release note: None

#### opt: add slow-query-6

Release note: None

#### opt: add two reorder_join_limit cases for BenchmarkSlowQueries

`BenchmarkSlowQueries` now runs each slow query benchmark with
`reorder_join_limit` set to `0` and `8`. This will allow us to analyze
the range of query optimization performance with respect to this setting
which is commonly adjusted to reduce planning latency.

Release note: None

#### opt: avoid FuncDepSet.tryToReduceKey in FuncDepSet.addEquivalency

Prior to this commit, `FuncDepSet.tryToReduceKey` was called at the end
of `FuncDepSet.addEquivalency`. This was inefficient because
`FuncDepSet.AddFrom` and `FuncDepSet.AddEquivFrom` can call
`addEquivalency` multiple times, and the FD's key only needs to be
reduced after all equivalencies and dependencies have been added. Now,
`tryToReduceKey` is no longer called in `addEquivalency` and callers are
responsible for ensuring that it is called. This mimics the behavior of
the similar function `addDependency`.

Release note: None

#### opt: add `FuncDepSet.addConstantsNoKeyReduction`

This commit adds a new method `FuncDepSet.addConstantsNoKeyReduction`
which is the same as `FuncDepSet.AddConstants`, only differing because
it not attempt to reduce the key like `AddConstants does. This allows us
to avoid key-reducing computation in a few places.

Release note: None

#### opt: use `ComputeEquivClosureNoCopy` in `FuncDepSet.addEquivalency`

This commit changes the invocation of `ComputeEquivClosure` within
`FuncDepSet.addEquivalency` to `ComputeEquivClosureNoCopy`. This is
valid because `addEquivalency` is only called with sets that have
already been copied, so mutating the input set is safe.

Release note: None

#### opt: avoid ColSet allocations in statisticsBuilder.colStatJoin

This commit reduces allocation in `statisticsBuilder.colStatJoin`.
Previously, it was creating intersections of two sets, which, in some
cases, were only useful for checking their emptiness. Now we use the
`ColSet.Intersects` method which returns a boolean and does not
build a new set.

Release note: None

#### opt: reduce allocations in statistic builder

This commit reduces allocations in the statistics builder by avoiding
creating singleton column sets. A new `ColStatsMap.LookupSingleton`
method allows columns stats for a single column to be fetched without
building a column set and potentially allocating memory.

Epic: None

Release note: None


Co-authored-by: Marcus Gartner <[email protected]>
  • Loading branch information
craig[bot] and mgartner committed Nov 17, 2023
2 parents 557264e + 97112ff commit 44cefdf
Show file tree
Hide file tree
Showing 10 changed files with 1,784 additions and 1,020 deletions.
2 changes: 2 additions & 0 deletions pkg/sql/opt/bench/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_test(
"fk_test.go",
"uniq_test.go",
],
data = glob(["testdata/**"]),
embed = [":bench"],
deps = [
"//pkg/base",
Expand All @@ -38,6 +39,7 @@ go_test(
"//pkg/sql/sem/eval",
"//pkg/sql/sem/tree",
"//pkg/sql/sem/volatility",
"//pkg/testutils/datapathutils",
"//pkg/testutils/serverutils",
"//pkg/testutils/sqlutils",
"//pkg/util/log",
Expand Down
Loading

0 comments on commit 44cefdf

Please sign in to comment.