-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql/stats: after inject or restore of partial statistics, cannot create merged statistics #94101
Comments
Good news is that we are including partial statistics in statement bundles, so the first part is already done. Bad news is that the second part still needs work. After CREATE TABLE uw (name TEXT PRIMARY KEY, location GEOGRAPHY(POINT)) WITH (sql_stats_automatic_collection_enabled = false);
INSERT INTO uw VALUES ('Washington', 'POINT(-122.30 47.66)'), ('Waterloo', 'POINT(-80.54 43.47)'), ('Wisconsin', 'POINT(-89.42 43.08)');
CREATE STATISTICS uwfull FROM uw;
INSERT INTO uw VALUES ('Warsaw', 'POINT(21.02 52.24)'), ('Winnipeg', 'POINT(-97.15 49.89)'), ('Wyoming', 'POINT(-105.57 41.31)');
CREATE STATISTICS uwpartial ON name FROM uw USING EXTREMES;
SHOW STATISTICS FOR TABLE uw WITH MERGE;
EXPLAIN SELECT * FROM uw;
EXPLAIN ANALYZE (DEBUG) SELECT * FROM uw;
-- Then download and unzip the bundle, and run `cockroach debug statement-bundle recreate`. In that session:
SHOW STATISTICS FOR TABLE uw WITH MERGE;
EXPLAIN SELECT * FROM uw; Before recreating the bundle this looks like:
After recreating the bundle we're missing the merged stats:
I'm going to change this issue to be about this second problem. |
As a workaround we can fix the restored / injected partial statistics with something like: UPDATE
system.table_statistics AS p
SET
"fullStatisticID"
= (
SELECT
"statisticID"
FROM
system.table_statistics AS f
WHERE
f."tableID" = p."tableID"
AND f."columnIDs" = p."columnIDs"
AND f."createdAt" < p."createdAt"
AND f."partialPredicate" IS NULL
ORDER BY
f."createdAt" DESC
LIMIT
1
)
WHERE
p."tableID" = 'uw'::REGCLASS::INT8
AND p."createdAt" > '2023-01-13'
AND p."partialPredicate" IS NOT NULL
RETURNING
p."tableID",
p."columnIDs",
p.name,
p."statisticID",
p."fullStatisticID"; But this won't always be correct, so I think it would be better to really fix this. Probably by changing cockroach/pkg/sql/stats/new_stat.go Lines 102 to 122 in 6f5d89e
|
Previously, JSON statistics would not include the statistic ID. This meant that restoring statement bundles would recreate stats with new IDs, breaking the statisticID/fullStatisticID relationship between full & partial stats and fail to recreate merged stats as a result. This commit adds the statistic ID to JSONStatistic and recreates stats with the same ID if present when injected. Allows for merged stats to be correctly recreated following inject/restore of full and partial stats. Fixes: cockroachdb#94101 See also: cockroachdb#125950 Release note (bug fix): Fixed a bug that prevented merged stats from being created after injecting stats or recreating statement bundles. This would occur when the injected stats/statement bundle contained related full and partial statistics.
127155: github: fix check-pebble-dep action r=RaduBerinde a=RaduBerinde The action is failing with `invalid object name 'origin/release-23.1'` This commit adds `fetch-depth: 0` which enables use of all branches. Epic: none Release note: None 127252: sql/stats: fix inject/restore of partial stats not creating merged stats r=Uzair5162 a=Uzair5162 Previously, JSON statistics would not include the statistic ID. This meant that restoring statement bundles would recreate stats with new IDs, breaking the statisticID/fullStatisticID relationship between full & partial stats and fail to recreate merged stats as a result. This commit adds the statistic ID to JSONStatistic and recreates stats with the same ID if present when injected. Allows for merged stats to be correctly recreated following inject/restore of full and partial stats. Fixes: #94101 See also: #125950 Release note (bug fix): Fixed a bug that prevented merged stats from being created after injecting stats or recreating statement bundles. This would occur when the injected stats/statement bundle contained related full and partial statistics. Co-authored-by: Radu Berinde <radu@cockroachlabs.com> Co-authored-by: Uzair Ahmad <uzair.ahmad@cockroachlabs.com>
Now that users can collect partial statistics at the extremes of columns using
CREATE STATISTICS ON <col_name> FROM <table_name> USING EXTREMES
, ensure that statements bundles include both full statistics and partial statistics.The other thing we need to be sure of is that merged statistics are correctly created when injecting statment bundle stats so that we can mimic customer behavior.
Jira issue: CRDB-22695
Epic CRDB-25383
The text was updated successfully, but these errors were encountered: