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 qualified index name resolution #24778

Merged
merged 1 commit into from
Apr 16, 2018

Conversation

knz
Copy link
Contributor

@knz knz commented Apr 13, 2018

Fixes #24475.
cc @nvanbenschoten

In CockroachDB index names are relative to a table name
(e.g. tbl@idx) but in Postgres index names live in the schema
namespace. To offer compatibility with Postgres, CockroachDB
implements a special name resolution algorithm for index names
specified without the '@' syntax. For example, DROP INDEX foo will
search all tables in the current schema to find one with index name
foo.

Prior to this patch, CockroachDB was not able to search for a
qualified index name specified without the '@' syntax. For example,
TypeORM issues DROP INDEX public."primary", expecting to be able to
drop the primary index of some table in the public schema. This was
not recognized by CockroachDB.

This patch extends the name resolution for index names to support both
partial and complete qualification, using the same name resolution
rules as other objects.

Release note (sql change): CockroachDB now supports more ways to
specify an index name for statements that require one (e.g., DROP INDEX, ALTER INDEX ... RENAME, etc.), in a way more compatible with
PostgreSQL.

@knz knz requested review from justinj and a team April 13, 2018 10:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@knz
Copy link
Contributor Author

knz commented Apr 13, 2018

This will need a cherry-pick.

@knz
Copy link
Contributor Author

knz commented Apr 13, 2018

@nvanbenschoten could you try, or help me try, TypeORM with this fix in? To see if it improves the situation.

@knz knz requested a review from a team April 13, 2018 11:34
// false, otherwise err would be non-nil.
return nil, nil, nil
} else if foundTn != nil {
// Memoize the table name that was found.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment still true? Doesn't look like we're sticking anything onto the struct anymore, unless tn points into the struct as a result of having been returned from Normalize, which I think would merit a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is still true. I added a comment.

@knz knz force-pushed the 20180413-resolve-idx branch 2 times, most recently from 314395f to f9595d6 Compare April 15, 2018 18:51
In CockroachDB index names are relative to a table name
(e.g. `tbl@idx`) but in Postgres index names live in the schema
namespace. To offer compatibility with Postgres, CockroachDB
implements a special name resolution algorithm for index names
specified without the '@' syntax. For example, `DROP INDEX foo` will
search all tables in the current schema to find one with index name
`foo`.

Prior to this patch, CockroachDB was not able to search for a
_qualified_ index name specified without the '@' syntax. For example,
TypeORM issues `DROP INDEX public."primary"`, expecting to be able to
drop the primary index of some table in the `public` schema. This was
not recognized by CockroachDB.

This patch extends the name resolution for index names to support both
partial and complete qualification, using the same name resolution
rules as other objects.

Release note (sql change): CockroachDB now supports more ways to
specify an index name for statements that require one (e.g., `DROP
INDEX`, `ALTER INDEX ... RENAME`, etc.), in a way more compatible with
PostgreSQL.
@knz
Copy link
Contributor Author

knz commented Apr 16, 2018

bors r+

craig bot pushed a commit that referenced this pull request Apr 16, 2018
24778: sql: fix qualified index name resolution r=knz a=knz

Fixes #24475.
cc @nvanbenschoten 

In CockroachDB index names are relative to a table name
(e.g. `tbl@idx`) but in Postgres index names live in the schema
namespace. To offer compatibility with Postgres, CockroachDB
implements a special name resolution algorithm for index names
specified without the '@' syntax. For example, `DROP INDEX foo` will
search all tables in the current schema to find one with index name
`foo`.

Prior to this patch, CockroachDB was not able to search for a
_qualified_ index name specified without the '@' syntax. For example,
TypeORM issues `DROP INDEX public."primary"`, expecting to be able to
drop the primary index of some table in the `public` schema. This was
not recognized by CockroachDB.

This patch extends the name resolution for index names to support both
partial and complete qualification, using the same name resolution
rules as other objects.

Release note (sql change): CockroachDB now supports more ways to
specify an index name for statements that require one (e.g., `DROP
INDEX`, `ALTER INDEX ... RENAME`, etc.), in a way more compatible with
PostgreSQL.

Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Apr 16, 2018

Build succeeded

@craig craig bot merged commit 37def3f into cockroachdb:master Apr 16, 2018
@knz knz deleted the 20180413-resolve-idx branch April 16, 2018 04:34
@knz knz restored the 20180413-resolve-idx branch April 16, 2018 04:34
@knz knz deleted the 20180413-resolve-idx branch April 16, 2018 05:33
@nvanbenschoten
Copy link
Member

@knz yeah, this seems to have fixed the issue with TypeORM. Thanks!

craig bot pushed a commit that referenced this pull request Apr 16, 2018
24817: cherrypick-2.0: sql: fix qualified index name resolution r=knz a=knz

Picks #24778.
cc @cockroachdb/release 

24842: cherry-pick 2.0: sql: use a reusable name resolution algo for star expansions r=knz a=knz

Picks #24811.
cc @cockroachdb/release 

Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
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.

4 participants