Skip to content

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

Merged
craig[bot] merged 4 commits intocockroachdb:masterfrom
jayshrivastava:add-fk-and-unique-constraints
Dec 22, 2020
Merged

workload/schemachange: add fk constraints and type improvements #58065
craig[bot] merged 4 commits intocockroachdb:masterfrom
jayshrivastava:add-fk-and-unique-constraints

Conversation

@jayshrivastava
Copy link
Copy Markdown
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
Copy Markdown
Member

This change is Reviewable

@jayshrivastava jayshrivastava force-pushed the add-fk-and-unique-constraints branch from 137e3a0 to 5aba7a0 Compare December 18, 2020 16:25
@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
Copy Markdown
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
@jayshrivastava jayshrivastava force-pushed the add-fk-and-unique-constraints branch from bd59fd8 to 4c9ef83 Compare December 22, 2020 15:31
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 jayshrivastava force-pushed the add-fk-and-unique-constraints branch from 4c9ef83 to 0265965 Compare December 22, 2020 16:41
@jayshrivastava
Copy link
Copy Markdown
Contributor Author

bors r=ajwerner

@craig
Copy link
Copy Markdown
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