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

sqlsmith: enhance tlp to test predicate projections and DISTINCTs #73701

Merged
merged 2 commits into from
Feb 4, 2022

Conversation

jordanlewis
Copy link
Member

@jordanlewis jordanlewis commented Dec 10, 2021

This commit enhances the WHERE tlp generator to also output the
projection of the predicates in both the partitioned and unpartitioned
query outputs. The purpose of this enhanced testing is to make sure that
projection output always matches filter output, and that projection
output for all 3 partitions is identical in every partition and in the
non-partitioned case as well.

Also, add a DISTINCT oracle.

The DISTINCT oracle for TLP generates unpartitioned queries of the
following form:

SELECT DISTINCT {cols...} FROM t

and partitioned queries of the following form:

SELECT DISTINCT {cols...} FROM t WHERE pred UNION ALL
SELECT DISTINCT {cols...} FROM t WHERE NOT (pred) UNION ALL
SELECT DISTINCT {cols...} FROM t WHERE (pred) IS NULL

Release note: None

@jordanlewis jordanlewis requested a review from mgartner December 10, 2021 22:27
@jordanlewis jordanlewis requested a review from a team as a code owner December 10, 2021 22:27
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jordanlewis
Copy link
Member Author

Hi @mgartner, I wrote this extra testing as a way to start understanding TLP a bit better. I think it does test some new things, since the path for projections is different from the path for filters. But, maybe it's not novel enough to add? I'm not sure, interested to see what you think.

@jordanlewis jordanlewis changed the title sqlsmith: enhance tlp to test predicate projections sqlsmith: enhance tlp to test predicate projections and DISTINCTs Dec 10, 2021
@jordanlewis
Copy link
Member Author

Second commit adds the DISTINCT oracle given by Manuel's paper.

@jordanlewis
Copy link
Member Author

Gentle ping on this if you have some time to take a look!

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

Very cool! Sorry for the delay. :lgtm: , just left some minor suggestions.

Reviewed 1 of 1 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis)


pkg/internal/sqlsmith/tlp.go, line 65 at r1 (raw file):

// The first query returned is an unpartitioned query of the form:
//
//   SELECT *, p, NOT (p), (p) IS NULL, true, false, false FROM table

I'm not sure the last three columns are necessary. Is there a type of bug you have in mind that they would catch that would not be caught by the addition of the first three columns?


pkg/internal/sqlsmith/tlp.go, line 109 at r1 (raw file):

FROM %s
WHERE %s`, allPreds, pred1, pred2, pred3, tableName, pred1)
	part2 := fmt.Sprintf(`SELECT *, 

nit: remove trailing whitespace


pkg/internal/sqlsmith/tlp.go, line 392 at r2 (raw file):

//
//   SELECT DISTINCT {cols...} FROM table WHERE (p) UNION ALL
//   SELECT DISTINCT {cols...} FROM table WHERE NOT (p) UNION ALL

If you change the UNION ALLs to UNIONs, then you don't need the to return a distinct boolean above and you can remove de-duplicating code from unsortedMatrixesDiff.

Copy link
Member Author

@jordanlewis jordanlewis 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 (and 1 stale) (waiting on @mgartner)


pkg/internal/sqlsmith/tlp.go, line 65 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

I'm not sure the last three columns are necessary. Is there a type of bug you have in mind that they would catch that would not be caught by the addition of the first three columns?

I added this because if there's some way an entire column was be projected to the incorrect boolean, we'd have false passes. I guess it's an implausible case though?


pkg/internal/sqlsmith/tlp.go, line 392 at r2 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

If you change the UNION ALLs to UNIONs, then you don't need the to return a distinct boolean above and you can remove de-duplicating code from unsortedMatrixesDiff.

Good point, done.

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

:lgtm_strong:

Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis)


pkg/internal/sqlsmith/tlp.go, line 65 at r1 (raw file):

Previously, jordanlewis (Jordan Lewis) wrote…

I added this because if there's some way an entire column was be projected to the incorrect boolean, we'd have false passes. I guess it's an implausible case though?

🤷 Hard to say how plausible that is. I'm fine keeping it. Might be explaining the columns in this comment though.

This commit enhances the WHERE tlp generator to also output the
projection of the predicates in both the partitioned and unpartitioned
query outputs. The purpose of this enhanced testing is to make sure that
projection output always matches filter output, and that projection
output for all 3 partitions is identical in every partition and in the
non-partitioned case as well.

Release note: None
The DISTINCT oracle for TLP generates unpartitioned queries of the
following form:

SELECT DISTINCT {cols...} FROM t

and partitioned queries of the following form:

SELECT DISTINCT {cols...} FROM t WHERE pred UNION ALL
SELECT DISTINCT {cols...} FROM t WHERE NOT (pred) UNION ALL
SELECT DISTINCT {cols...} FROM t WHERE (pred) IS NULL

Release note: None
Copy link
Member Author

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

TFTR!

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)


pkg/internal/sqlsmith/tlp.go, line 65 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

🤷 Hard to say how plausible that is. I'm fine keeping it. Might be explaining the columns in this comment though.

Done.

@jordanlewis
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 4, 2022

Build succeeded:

@craig craig bot merged commit b51c9b4 into cockroachdb:master Feb 4, 2022
@jordanlewis jordanlewis deleted the tlp-projections branch February 25, 2022 17:10
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.

3 participants