fix: include schema when creating indices#637
Merged
olavloite merged 2 commits intogoogleapis:mainfrom May 2, 2025
Merged
Conversation
7b0af8e to
2936ea3
Compare
Fixes an issue where indices aren't able to be created for tables in schemas. At present, `vist_create_index` emits SQL like ```sql CREATE INDEX index_name (col) ON schema_name.table_name ``` which results in an error when creating the table: ``` Index index_name cannot index a table/index schema_name.table_name which is in a different named schema. ``` because the name needs to be prefixed by schema. `vist_drop_index` does emit the correct SQL with the schema prefix. ```sql DROP INDEX schema_name.index_name ``` This is due to an odd issue where the base class's `visit_create_index` method has in its signature `include_schema=False`: https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/sql/compiler.py#L6828C23-L6828C43 but `visit_drop_index` hard-codes the value to `True`: https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/sql/compiler.py#L6870 The dialects handle this by hard-coding `include_schema=True` in `visit_create_index`, e.g. sqlite: https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/dialects/sqlite/base.py#L1740 The difference in defaults is odd in the base class, but it seems like include_schema=True is the appropriate setting for Spanner.
2936ea3 to
2d1c08b
Compare
2a0f34f to
f65a0b7
Compare
olavloite
approved these changes
May 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an issue where indices aren't able to be created for tables in schemas. At present,
create_indexemits SQL likewhich results in an error when creating the table:
because the name needs to be prefixed by schema.
drop_indexdoes emit the correct SQL with the schema prefix.This is due to an odd issue where the base class's
visit_create_indexmethod has in its signatureinclude_schema=False:https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/sql/compiler.py#L6828C23-L6828C43
but
visit_drop_indexhard-codes the value toTrue:https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/sql/compiler.py#L6870
The dialects handle this by hard-coding
include_schema=Trueinvisit_create_index, e.g.sqlite:
https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/dialects/sqlite/base.py#L1740
The difference in defaults is odd in the base class, but it seems like include_schema=True is the appropriate setting for Spanner.
Part of #638