-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give query case sensitive treatment in query hash (#4254)
Generating the query hash from the query text with no lowercasing of the query text allows case-sensitive parameter values in the dashboard to have different cache entries. Fixes #2137
- Loading branch information
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
migrations/versions/1038c2174f5d_make_case_insensitive_hash_of_query_text.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Make case insensitive hash of query text | ||
Revision ID: 1038c2174f5d | ||
Revises: fd4fc850d7ea | ||
Create Date: 2023-07-16 23:10:12.885949 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.sql import table | ||
|
||
from redash.utils import gen_query_hash | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '1038c2174f5d' | ||
down_revision = 'fd4fc850d7ea' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
|
||
def change_query_hash(conn, table, query_text_to): | ||
for record in conn.execute(table.select()): | ||
query_text = query_text_to(record.query) | ||
conn.execute( | ||
table | ||
.update() | ||
.where(table.c.id == record.id) | ||
.values(query_hash=gen_query_hash(query_text))) | ||
|
||
|
||
def upgrade(): | ||
queries = table( | ||
'queries', | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('query', sa.Text), | ||
sa.Column('query_hash', sa.String(length=10))) | ||
|
||
conn = op.get_bind() | ||
change_query_hash(conn, queries, query_text_to=str) | ||
|
||
|
||
def downgrade(): | ||
queries = table( | ||
'queries', | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('query', sa.Text), | ||
sa.Column('query_hash', sa.String(length=10))) | ||
|
||
conn = op.get_bind() | ||
change_query_hash(conn, queries, query_text_to=str.lower) |
This file contains 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