Skip to content

Commit 11ca80b

Browse files
committed
Fixing fingerprinting of table arguments
Queries that select from the same table but with different arguments for hidden columns (most notably `SELECT * FROM comdb2_transaction_logs('{file:offset}')`) are fingerprinted uniquely. This patch fixes it. Signed-off-by: Rivers Zhang <[email protected]>
1 parent 4241556 commit 11ca80b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Diff for: sqlite/src/tokenize.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -835,13 +835,14 @@ static int isLeftOperand(int tokenType){
835835
** This function should return non-zero if the specified token type is
836836
** a keyword that requires the next token to be a table identifier.
837837
*/
838-
static int requiresTableId(int tokenType){
838+
static int requiresTableId(int tokenType, int useStrId){
839839
switch( tokenType ){
840840
case TK_FROM:
841841
case TK_JOIN:
842842
case TK_INTO:
843843
case TK_UPDATE:
844844
case TK_TABLE: return 1;
845+
case TK_SPACE: return useStrId;
845846
default: return 0;
846847
}
847848
}
@@ -964,7 +965,6 @@ char *sqlite3Normalize_alternate(
964965
/* fall through */
965966
}
966967
default: {
967-
useStrId = requiresTableId(tokenType);
968968
if( sqlite3IsIdChar(zSql[i]) ) addSpaceSeparator(pStr);
969969
j = pStr->nChar;
970970
sqlite3_str_append(pStr, zSql+i, n);
@@ -975,6 +975,7 @@ char *sqlite3Normalize_alternate(
975975
break;
976976
}
977977
}
978+
useStrId = requiresTableId(tokenType, useStrId);
978979
}
979980
if( tokenType!=TK_SEMI ) sqlite3_str_append(pStr, ";", 1);
980981
return sqlite3_str_finish(pStr);

Diff for: tests/fingerprints.test/t08.req

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT * FROM 'sqlite_stat1' LIMIT 0 -- should show table name
2+
SELECT * FROM comdb2_transaction_logs('{1:0}') LIMIT 0 -- should not show arguments for hidden columns
3+
SELECT fingerprint, normalized_sql FROM comdb2_fingerprints WHERE fingerprint='002dcfc6d511a5d625fa142f7f0df9f4'
4+
SELECT fingerprint, normalized_sql FROM comdb2_fingerprints WHERE fingerprint='c30b0528f036eab64a7953ed7c55af40'

Diff for: tests/fingerprints.test/t08.req.out

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(fingerprint='002dcfc6d511a5d625fa142f7f0df9f4', normalized_sql='SELECT*FROM sqlite_stat1 LIMIT?;')
2+
(fingerprint='c30b0528f036eab64a7953ed7c55af40', normalized_sql='SELECT*FROM comdb2_transaction_logs(?)LIMIT?;')

0 commit comments

Comments
 (0)