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

sql: Fix create partial stats test cases #92617

Merged

Conversation

faizaanmadhani
Copy link
Contributor

@faizaanmadhani faizaanmadhani commented Nov 28, 2022

This commit modifies the create partial statistics test cases to ensure that the full table statistics that are to be used to create a partial statistic exist in the cache. Previously, this was not the case so certain tests had non-deterministic outputs causing failures in stress tests.

Resolves: #92495 and #92559

Epic: CRDB-19449

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@faizaanmadhani faizaanmadhani marked this pull request as ready for review November 28, 2022 20:55
@faizaanmadhani faizaanmadhani requested a review from a team November 28, 2022 20:55
@faizaanmadhani faizaanmadhani requested a review from a team as a code owner November 28, 2022 20:55
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @faizaanmadhani, @mgartner, and @michae2)


pkg/sql/logictest/testdata/logic_test/distsql_stats line 2080 at r1 (raw file):

# Test null values.
statement ok
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;

nit: this should not be needed since we always disable auto stats in logic tests (see newCluster in logic.go) and in this file we don't enable them. What is the reason you included this? I'd guess that the bug you're fixing is due to table stats cache not being populated and not that some extra stats are being collected.

@faizaanmadhani faizaanmadhani force-pushed the faizaan/fix-distsql-regression branch from fce2a3d to b52f2a5 Compare November 28, 2022 21:32
@faizaanmadhani
Copy link
Contributor Author

pkg/sql/logictest/testdata/logic_test/distsql_stats line 2080 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: this should not be needed since we always disable auto stats in logic tests (see newCluster in logic.go) and in this file we don't enable them. What is the reason you included this? I'd guess that the bug you're fixing is due to table stats cache not being populated and not that some extra stats are being collected.

I didn't realize we already disabled this, but this shouldn't be here anyways. Since this is disabled by default I've also removed it from when it's disabled above as well.

Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

Nice, glad it worked!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @faizaanmadhani, @mgartner, and @yuzefovich)


pkg/sql/alter_table.go line 1379 at r1 (raw file):

	}

	if !settings.Version.IsActive(ctx, clusterversion.V23_1AddPartialStatisticsPredicateCol) {

If the JSONStatistics has a partial predicate, it would be wrong to insert it into table_statistics without the partial predicate, even if we haven't yet crossed the version gate. We need to throw an error if s.PartialPredicate != "".


pkg/sql/stats/new_stat.go line 106 at r1 (raw file):

					"nullCount",
					"avgSize",
					histogram

nit: was this already fixed in another PR?


pkg/sql/logictest/testdata/logic_test/distsql_stats line 2096 at r1 (raw file):


statement ok
ALTER TABLE a_null INJECT STATISTICS '$a_null_stats'

nit: Please leave comments at all of these ALTER TABLE INJECT STATISTICS here and below explaining that the purpose is to invalidate the stats cache.

Copy link
Contributor Author

@faizaanmadhani faizaanmadhani left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @michae2, and @yuzefovich)


pkg/sql/stats/new_stat.go line 106 at r1 (raw file):

Previously, michae2 (Michael Erickson) wrote…

nit: was this already fixed in another PR?

It was supposed to be fixed in #92419, but that PR hasn't been merged in yet because there's a test there that keeps timing out. In order the keep the changes separate I can merge in that PR first and then merge in this one.

@faizaanmadhani faizaanmadhani force-pushed the faizaan/fix-distsql-regression branch from b52f2a5 to 5be6fa8 Compare November 28, 2022 22:12
Copy link
Contributor Author

@faizaanmadhani faizaanmadhani left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @michae2, and @yuzefovich)


pkg/sql/alter_table.go line 1379 at r1 (raw file):

Previously, michae2 (Michael Erickson) wrote…

If the JSONStatistics has a partial predicate, it would be wrong to insert it into table_statistics without the partial predicate, even if we haven't yet crossed the version gate. We need to throw an error if s.PartialPredicate != "".

Done.

Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm: Thank you!

Reviewed 1 of 3 files at r1, 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @faizaanmadhani, @mgartner, and @yuzefovich)


pkg/sql/alter_table.go line 1382 at r3 (raw file):

		if s.PartialPredicate != "" {
			return pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, "statistic to insert is partial but cluster version is below 23.1")

nit: The injected statistics often contain dozens of objects, and can be several megabytes in size. Can we add something to this error message that helps identify which one was partial? Maybe the column name and the collection time?


pkg/sql/stats/new_stat.go line 106 at r1 (raw file):

Previously, faizaanmadhani (Faizaan Madhani) wrote…

It was supposed to be fixed in #92419, but that PR hasn't been merged in yet because there's a test there that keeps timing out. In order the keep the changes separate I can remove this change from this PR and we can merge in the other one first.

Sounds good!

@faizaanmadhani faizaanmadhani force-pushed the faizaan/fix-distsql-regression branch from 5be6fa8 to 084bbd6 Compare November 28, 2022 22:26
This commit modifies the create partial
statistics test cases to ensure that the full table
statistics that are to be used to create a partial
statistic exist in the cache. Previously, this was
not the case so certain tests had non-deterministic
outputs causes failures in stress tests.

Resolves: cockroachdb#92495

Epic: CRDB-19449

Release note: None
@faizaanmadhani faizaanmadhani force-pushed the faizaan/fix-distsql-regression branch from 084bbd6 to 81ae512 Compare November 29, 2022 15:14
@faizaanmadhani
Copy link
Contributor Author

TFTRs! 🎉

bors r=michae2

@craig craig bot merged commit edc6fda into cockroachdb:master Nov 29, 2022
@craig
Copy link
Contributor

craig bot commented Nov 29, 2022

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants