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

workload/schemachange: add fk constraints and type improvements #58065

Merged

Conversation

jayshrivastava
Copy link
Contributor

@jayshrivastava jayshrivastava commented Dec 18, 2020

workload/schemachange: implement addForeignKeyConstraint op

addForeignKeyConstraint adds a single, non-composite, foreign key relation
between two random columns.

Closes: #57472
Release note: None

workload/schemachange: implement addUniqueConstraint op

The addUniqueConstraint op adds a unique constraint on a single
column.

Release note: None

workload/schemachange: add oid type resolution to type resolver

Previously, the workload was failing because, in certain situations,
it would expect certain type errors and they would not occur. This was due
to the type resolver incorrectly resolving non user-defined types as enums.
This change adds some logic to properly resolve non user-defined types
by OID.

Closes: #57993
Release note: None

workload/schemachange: expect undefined table in create sequence

Previously, creating a sequence that was owned by a column
from a non existing table would cause an unexpected
pgcode.UndefinedTable. This change ensures that this error
is expected when the table does not exist.
Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jayshrivastava jayshrivastava marked this pull request as ready for review December 21, 2020 16:05
@jayshrivastava jayshrivastava force-pushed the add-fk-and-unique-constraints branch 2 times, most recently from 13c4fb8 to 3992d74 Compare December 21, 2020 17:22
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 4 files at r1, 2 of 2 files at r2, 1 of 1 files at r3, 1 of 1 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jayshrivastava)


pkg/workload/schemachange/error_screening.go, line 586 at r1 (raw file):

}

func violatesFkConstraintsHelper(

This could use a better name and a comment.


pkg/workload/schemachange/operation_generator.go, line 321 at r1 (raw file):

func (og *operationGenerator) addForeignKeyConstraint(tx *pgx.Tx) (string, error) {

	// Use og.produceError() to determine if errors will be produced due to the column being generated

Is this comment stale?


pkg/workload/schemachange/type_resolver.go, line 36 at r3 (raw file):

) (*types.T, error) {

	// An explicit schema indicates the type is a user defined enum type.

that's subtle and doesn't need to be the case. Comment on this function if you're going with that.


pkg/workload/schemachange/type_resolver.go, line 44 at r3 (raw file):

         AND typcategory = 'E'
         AND typname = $1
				 AND nspname = $2

nit: weird indentation


pkg/workload/schemachange/type_resolver.go, line 46 at r3 (raw file):

				 AND nspname = $2
ORDER BY enumsortorder`, name.Object(), name.Schema())
		fmt.Println(err, "ASDFASDF")

remove

addForeignKeyConstraint adds a single, non-composite, foreign key relation
between two random columns.

Release note: None
The addUniqueConstraint op adds a unique constraint on a single
column.

Release note: None
Previously, the workload was failing because, in certain situations,
it would expect certain type errors and they would not occur. This was due
to the type resolver incorrectly resolving non user-defined types as enums.
This change adds some logic to properly resolve non user-defined types
by OID.

Closes: cockroachdb#57993
Release note: None
Previously, creating a sequence that was owned by a column
from a non existing table would cause an unexpected
pgcode.UndefinedTable. This change ensures that this error
is expected when the table does not exist.
Release note: None
@jayshrivastava
Copy link
Contributor Author

bors r=ajwerner

@craig
Copy link
Contributor

craig bot commented Dec 22, 2020

Build succeeded:

@craig craig bot merged commit 9d87c5c into cockroachdb:master Dec 22, 2020
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.

workload/schemachange: upgrade resolver to resolve non-enum types workload/schemachange: add fk constraints
3 participants