-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
opt: add setting to always use histograms to calculate stats #98194
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 7 of 7 files at r1, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @michae2)
Looks like it just needs some of the session var tests regenerated. |
Informs cockroachdb#64570 Release note (sql change): Added a new session setting, optimizer_always_use_histograms, which ensures that the optimizer always uses histograms when available to calculate the statistics of every plan that it explores. Enabling this setting can prevent the optimizer from choosing a suboptimal index when statistics for a table are stale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 7 of 7 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @rytaft)
I think this is great, but noting that I think I found a case where this does not fix the problem: CREATE TABLE abc (a INT, b INT, c STRING, UNIQUE INDEX (a), INDEX (b)) WITH (sql_stats_automatic_collection_enabled = false);
INSERT INTO abc SELECT unordered_unique_rowid(), i, REPEAT('c', 2048) FROM generate_series(0, 32767) s(i);
ANALYZE abc;
INSERT INTO abc VALUES (4000000000000000000, 40000, '');
EXPLAIN (OPT, VERBOSE) SELECT * FROM abc WHERE a = 4000000000000000000 AND b = 40000; This picks the index on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTRs!
I think I found a case where this does not fix the problem
Yea... this definitely isn't going to fix everything. But seems like it will still fix a lot of things. I'm going to go ahead and merge this and let's keep thinking about ways to chip away at these edge cases... Thanks for finding this one!
bors r+
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @rytaft)
Build succeeded: |
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. error creating merge commit from ef1604f to blathers/backport-release-22.1-98194: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 22.1.x failed. See errors above. error creating merge commit from ef1604f to blathers/backport-release-22.2-98194: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 22.2.x failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Reviewed 7 of 7 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale)
pkg/sql/vars.go
line 2533 at r2 (raw file):
return formatBoolAsPostgresSetting(evalCtx.SessionData().OptimizerAlwaysUseHistograms), nil }, GlobalDefault: globalFalse,
@rytaft, would it make sense to enable this by default in v23.1?
Previously, michae2 (Michael Erickson) wrote…
I was thinking of adding another change which checks whether there are multiple indexes for the table, and always uses the histogram if so, but maybe it would be better to just enable it. I don't think the performance overhead in case of a single index is significant enough that this would be noticeable. |
Previously, rytaft (Rebecca Taft) wrote…
|
Informs #64570
Release note (sql change): Added a new session setting,
optimizer_always_use_histograms
, which ensures that the optimizer always uses histograms when available to calculate the statistics of every plan that it explores. Enabling this setting can prevent the optimizer from choosing a suboptimal index when statistics for a table are stale.