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

fix: Create index only if not exists during MySQL online store update #3905

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,28 @@ def update(

# We don't create any special state for the entities in this implementation.
for table in tables_to_keep:

table_name = _table_id(project, table)
index_name = f"{table_name}_ek"
cur.execute(
f"""CREATE TABLE IF NOT EXISTS {_table_id(project, table)} (entity_key VARCHAR(512),
f"""CREATE TABLE IF NOT EXISTS {table_name} (entity_key VARCHAR(512),
feature_name VARCHAR(256),
value BLOB,
event_ts timestamp NULL DEFAULT NULL,
created_ts timestamp NULL DEFAULT NULL,
PRIMARY KEY(entity_key, feature_name))"""
)

cur.execute(
f"ALTER TABLE {_table_id(project, table)} ADD INDEX {_table_id(project, table)}_ek (entity_key);"
index_exists = cur.execute(
f"""
SELECT 1 FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = '{table_name}' AND index_name = '{index_name}'
"""
)
if not index_exists:
cur.execute(
f"ALTER TABLE {table_name} ADD INDEX {index_name} (entity_key);"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As MySQL does not support ADD INDEX IF NOT EXISTS, a separate query is created to handle this.


for table in tables_to_delete:
_drop_table_and_index(cur, project, table)
Expand Down
Loading