Skip to content

Commit b318b60

Browse files
Merge 59499db into blathers/backport-release-25.4-155864
2 parents 8f9084b + 59499db commit b318b60

File tree

20 files changed

+221
-0
lines changed

20 files changed

+221
-0
lines changed

pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

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

pkg/ccl/logictestccl/tests/local-read-committed/generated_test.go

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

pkg/ccl/logictestccl/tests/local-repeatable-read/generated_test.go

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

pkg/sql/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ go_library(
442442
"//pkg/sql/faketreeeval",
443443
"//pkg/sql/flowinfra",
444444
"//pkg/sql/gcjob/gcjobnotifier",
445+
"//pkg/sql/hintpb",
445446
"//pkg/sql/hints",
446447
"//pkg/sql/idxrecommendations",
447448
"//pkg/sql/idxusage",

pkg/sql/faketreeeval/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go_library(
1111
"//pkg/roachpb",
1212
"//pkg/security/username",
1313
"//pkg/sql/catalog/descpb",
14+
"//pkg/sql/hintpb",
1415
"//pkg/sql/pgwire/pgcode",
1516
"//pkg/sql/pgwire/pgerror",
1617
"//pkg/sql/pgwire/pgnotice",

pkg/sql/faketreeeval/evalctx.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/cockroachdb/cockroach/pkg/roachpb"
1616
"github.com/cockroachdb/cockroach/pkg/security/username"
1717
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
18+
"github.com/cockroachdb/cockroach/pkg/sql/hintpb"
1819
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
1920
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
2021
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgnotice"
@@ -589,6 +590,13 @@ func (ep *DummyEvalPlanner) ProcessVectorIndexFixups(
589590
return nil
590591
}
591592

593+
// InsertStatementHint is part of the eval.Planner interface.
594+
func (ep *DummyEvalPlanner) InsertStatementHint(
595+
ctx context.Context, statementFingerprint string, hint hintpb.StatementHintUnion,
596+
) (int64, error) {
597+
return 0, nil
598+
}
599+
592600
// DummyPrivilegedAccessor implements the tree.PrivilegedAccessor interface by returning errors.
593601
type DummyPrivilegedAccessor struct{}
594602

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# LogicTest: !local-mixed-25.2 !local-mixed-25.3
2+
3+
statement ok
4+
CREATE TABLE xy (x INT PRIMARY KEY, y INT, INDEX (y));
5+
6+
statement ok
7+
CREATE TABLE ab (a INT PRIMARY KEY, b INT, INDEX (b));
8+
9+
query I
10+
SELECT count(*) FROM system.statement_hints;
11+
----
12+
0
13+
14+
let $hint1
15+
SELECT crdb_internal.inject_hint(
16+
'SELECT * FROM xy WHERE y = 10',
17+
'SELECT * FROM xy@primary WHERE y = 10'
18+
);
19+
20+
# Verify that the returned hint ID is in the table.
21+
query T
22+
SELECT fingerprint FROM system.statement_hints WHERE row_id = $hint1;
23+
----
24+
SELECT * FROM xy WHERE y = 10
25+
26+
let $hint2
27+
SELECT crdb_internal.inject_hint(
28+
'SELECT * FROM xy WHERE y = 10',
29+
'SELECT * FROM xy@xy_y_idx WHERE y = 10'
30+
);
31+
32+
# Verify that the returned hint ID is in the table.
33+
query T
34+
SELECT fingerprint FROM system.statement_hints WHERE row_id = $hint2;
35+
----
36+
SELECT * FROM xy WHERE y = 10
37+
38+
let $hint3
39+
SELECT crdb_internal.inject_hint(
40+
'SELECT * FROM xy INNER JOIN ab ON xy.x = ab.b',
41+
'SELECT * FROM xy INNER JOIN ab ON xy.x = ab.b'
42+
);
43+
44+
# Verify that the returned hint ID is in the table.
45+
query T
46+
SELECT fingerprint FROM system.statement_hints WHERE row_id = $hint3;
47+
----
48+
SELECT * FROM xy INNER JOIN ab ON xy.x = ab.b
49+
50+
query I
51+
SELECT count(*) FROM system.statement_hints;
52+
----
53+
3
54+
55+
query I
56+
SELECT count(*) FROM system.statement_hints WHERE fingerprint = 'SELECT * FROM xy WHERE y = 10';
57+
----
58+
2
59+
60+
query I
61+
SELECT count(*) FROM system.statement_hints WHERE fingerprint = 'SELECT * FROM xy INNER JOIN ab ON xy.x = ab.b';
62+
----
63+
1
64+
65+
statement ok
66+
DELETE FROM system.statement_hints WHERE true;
67+
68+
query I
69+
SELECT count(*) FROM system.statement_hints;
70+
----
71+
0
72+
73+
# If the surrounding transaction is rolled back, no hint should be inserted.
74+
statement ok
75+
BEGIN;
76+
77+
let $hint4
78+
SELECT crdb_internal.inject_hint(
79+
'SELECT * FROM xy WHERE y = 10',
80+
'SELECT * FROM xy@{NO_FULL_SCAN} WHERE y = 10'
81+
);
82+
83+
query T
84+
SELECT fingerprint FROM system.statement_hints WHERE row_id = $hint4;
85+
----
86+
SELECT * FROM xy WHERE y = 10
87+
88+
statement ok
89+
ROLLBACK;
90+
91+
query I
92+
SELECT count(*) FROM system.statement_hints;
93+
----
94+
0

pkg/sql/logictest/tests/fakedist-disk/generated_test.go

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

pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go

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

pkg/sql/logictest/tests/fakedist/generated_test.go

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

0 commit comments

Comments
 (0)