Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idx histogram manipulation #2142

Merged
merged 14 commits into from
Nov 13, 2023
Merged

Idx histogram manipulation #2142

merged 14 commits into from
Nov 13, 2023

Conversation

max-hoffman
Copy link
Contributor

@max-hoffman max-hoffman commented Nov 10, 2023

Add simple histogram mutators for filter types. Use histogram costs for index selection when available. Added stats docs.

Dolt enginetests seem to be passing. Companion here: dolthub/dolt#6997

TODO:

  • I'd like to block statistics when only partially provided
  • TPCC plans are changed and I want to revert. Blocking partial statistics might fix those, I'm trying to get all of the actual index statistics for those tables as a better enginetest/blog example.

@max-hoffman max-hoffman marked this pull request as ready for review November 10, 2023 20:54
@max-hoffman max-hoffman requested a review from fulghum November 10, 2023 21:09
Copy link
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The doc.go content was really nice – very helpful to readers to explain those major concepts.

I didn't dig into the tpcc plan changes, since I'm assuming they'll get reverted when you start ignoring partial statistic info.

Looks like you're still adding some tests and the safety check for partial stats; let me know if you want me to take another look at any of that. Everything here looked pretty solid.

sql/stats/statistic.go Outdated Show resolved Hide resolved
@@ -130,6 +134,43 @@ func (s *Statistic) Histogram() sql.Histogram {
return buckets
}

func (s *Statistic) WithDistinct(i uint64) sql.Statistic {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(super minor/nit) WithDistinctCount would be a little more consistent with other method names (e.g. WithRowCount, WithNullCount).

@@ -98,6 +98,7 @@ type ScriptTestAssertion struct {

// CheckIndexedAccess indicates whether we should verify the query plan uses an index
CheckIndexedAccess bool
IndexName string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't dig into the details, but noticed we have an ExpectedIndexes []string field already. Seems like they're both trying to model the same thing. Any chance we can condense to just one?

@@ -0,0 +1,942 @@
package stats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package stats
// Copyright 2023 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package stats

statistic: x2Stat,
pref: []interface{}{5},
expBuckets: 2,
expRowCount: uint64(10),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just checking my understanding of the code... the BoundCnt param in Bucket indicates how many rows fall on the boundary (5 here), so would it be fair to say the expected row count is really 7 here instead of 10? (the 2 that fall on the boundary in the first bucket + the 5 in the next bucket)

Think that's something we can do to more accurately predict the cardinality when the prefix is equal to the boundary, or does that not work with other cases? (Or am I just misunderstanding the BoundCnt field? 😉)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is one of the optimizations that I missed a bit in this first version. Boundaries and most-common-value lists are keys+counts that should be checked to modify the distinct and count estimates more directly.

@max-hoffman max-hoffman merged commit d0a87ad into main Nov 13, 2023
7 checks passed
@Hydrocharged Hydrocharged deleted the max/idx-histogram-manipulation branch February 7, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants