Skip to content

Commit a49979e

Browse files
committed
logictest: add tests for loading external statement hints
Test that we're loading external statement hints correctly. Informs: #153633 Release note: None
1 parent 2c6258d commit a49979e

File tree

2 files changed

+87
-8
lines changed

2 files changed

+87
-8
lines changed

pkg/sql/logictest/testdata/logic_test/statement_hint_builtins

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# LogicTest: !local-mixed-25.2 !local-mixed-25.3
1+
# LogicTest: !local-mixed-25.2 !local-mixed-25.3 !local-prepared
22

33
statement ok
44
CREATE TABLE xy (x INT PRIMARY KEY, y INT, INDEX (y));
@@ -92,3 +92,89 @@ query I
9292
SELECT count(*) FROM system.statement_hints;
9393
----
9494
0
95+
96+
# Test that hints are loaded for matching statements.
97+
98+
statement ok
99+
SELECT crdb_internal.inject_hint(
100+
'SELECT * FROM xy WHERE x > y',
101+
'SELECT * FROM xy WHERE x > y'
102+
)
103+
104+
statement ok
105+
SELECT crdb_internal.await_statement_hints_cache()
106+
107+
statement ok
108+
SELECT * FROM xy WHERE x > y
109+
110+
query I
111+
SELECT usage_count
112+
FROM crdb_internal.feature_usage
113+
WHERE feature_name = 'sql.session.statement-hints'
114+
----
115+
1
116+
117+
statement ok
118+
EXPLAIN SELECT * FROM xy WHERE x > y
119+
120+
query I
121+
SELECT usage_count
122+
FROM crdb_internal.feature_usage
123+
WHERE feature_name = 'sql.session.statement-hints'
124+
----
125+
2
126+
127+
statement ok
128+
EXPLAIN ANALYZE SELECT * FROM xy WHERE x > y
129+
130+
query I
131+
SELECT usage_count
132+
FROM crdb_internal.feature_usage
133+
WHERE feature_name = 'sql.session.statement-hints'
134+
----
135+
3
136+
137+
statement ok
138+
PREPARE p AS SELECT * FROM xy WHERE x > y
139+
140+
statement ok
141+
EXECUTE p
142+
143+
query I
144+
SELECT usage_count
145+
FROM crdb_internal.feature_usage
146+
WHERE feature_name = 'sql.session.statement-hints'
147+
----
148+
5
149+
150+
statement ok
151+
SELECT crdb_internal.clear_statement_hints_cache()
152+
153+
statement ok
154+
SELECT * FROM xy WHERE x > y
155+
156+
query I
157+
SELECT usage_count
158+
FROM crdb_internal.feature_usage
159+
WHERE feature_name = 'sql.session.statement-hints'
160+
----
161+
6
162+
163+
statement ok
164+
DELETE FROM system.statement_hints WHERE true
165+
166+
statement ok
167+
SELECT crdb_internal.await_statement_hints_cache()
168+
169+
statement ok
170+
SELECT * FROM xy WHERE x > y
171+
172+
statement ok
173+
EXECUTE p
174+
175+
query I
176+
SELECT usage_count
177+
FROM crdb_internal.feature_usage
178+
WHERE feature_name = 'sql.session.statement-hints'
179+
----
180+
6

pkg/sql/logictest/tests/local-prepared/generated_test.go

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)