Skip to content

Conversation

@LuckySting
Copy link
Contributor

Description

YDB supports secondary indexes over the table, which may be used to optimize the selection of data.

In this PR

This PR contains the dialect features to declare and usage of YDB Secondary Indexes within SQLAlchemy Index and hints.

Example

Declaration

sa.Index("my_index", table.c.c2, ydb_async=True, ydb_cover=["c3"])

is rendered as

ALTER TABLE table ADD INDEX my_index GLOBAL ASYNC ON (c2) COVER (c3);

Usage

sa.select(
    sa.column(table.c.c1)
)
.select_from(table)
.where(sa.column(table.c.c2) == 1)
.with_hint(table, "VIEW `my_index`")

is rendered as

SELECT c1
FROM table VIEW `my_index`
WHERE c2 == 1


text = f"ALTER TABLE {table_name} ADD INDEX {index_name} GLOBAL"

text += " SYNC " if not ydb_opts.get("async", False) else " ASYNC"
Copy link
Member

Choose a reason for hiding this comment

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

SYNC wrapped with space from both side, ASYNC has no space at and - it seems as typo.

Copy link
Contributor Author

@LuckySting LuckySting Apr 22, 2024

Choose a reason for hiding this comment

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

Yes, there is a redundant space after the "SYNC" word. The tests don't fail because redundant spaces is not an error, but let's remove it

@rekby rekby merged commit 50f029a into ydb-platform:main Apr 22, 2024
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.

2 participants