Skip to content

Commit 8960c37

Browse files
craig[bot]jbowensmgartner
committed
147355: go.mod: bump Pebble to a38c80fb488e r=sumeerbhola a=jbowens Changes: * [`a38c80fb`](cockroachdb/pebble@a38c80fb) metrics: fix w-amp calculation w/ blob files * [`d742eb87`](cockroachdb/pebble@d742eb87) sstable: fix layout footer printing * [`bbcf0346`](cockroachdb/pebble@bbcf0346) crossversion: pass --previous-ops flag * [`20dbec1e`](cockroachdb/pebble@20dbec1e) metamorphic: sanity check initial-state and previous-ops flags * [`1b64b32e`](cockroachdb/pebble@1b64b32e) metamorphic: fix code around WAL recovery directories * [`3ec1b8da`](cockroachdb/pebble@3ec1b8da) metamorphic: use store-relative paths * [`138ec7ca`](cockroachdb/pebble@138ec7ca) db: support store-relative paths for WAL dirs * [`bd648617`](cockroachdb/pebble@bd648617) metamorphic: add random number to external object names * [`07c9d319`](cockroachdb/pebble@07c9d319) metamorphic: support CreateOnShared on existing store * [`2768d798`](cockroachdb/pebble@2768d798) metamorphic: use FS-based remote storage * [`4a2b3b81`](cockroachdb/pebble@4a2b3b81) metamorphic: update error blacklist Release note: none. Epic: none. 147368: opt: fix hints for placeholder fast path r=mgartner a=mgartner Fixes #147363 Release note (bug fix): A bug has been fixed that cause the optimizer to ignore index hints when optimizing some forms of prepared statements. This could result in one of two unexepcted behaviors: a query errors with the message "index cannot be used for this query" when the index can actually be used, or query using an index that does not adhere to the hint. The hints relevant to this bug are regular index hints, e.g., `SELECT * FROM tab@index`, `FORCE_INVERTED_INDEX` and `FORCE_ZIGZAG`. Co-authored-by: Jackson Owens <[email protected]> Co-authored-by: Marcus Gartner <[email protected]>
3 parents 4eb8e22 + 50f22cc + 572025d commit 8960c37

File tree

11 files changed

+93
-11
lines changed

11 files changed

+93
-11
lines changed

DEPS.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,10 +1895,10 @@ def go_deps():
18951895
patches = [
18961896
"@com_github_cockroachdb_cockroach//build/patches:com_github_cockroachdb_pebble.patch",
18971897
],
1898-
sha256 = "9c1327a1341d78784b000262f7497627d97d0f8e5e669c87a10165044deb6cd9",
1899-
strip_prefix = "github.com/cockroachdb/[email protected]20250523050552-abf8da2b6b97",
1898+
sha256 = "b6af4af1463c58e1058577c48aacb50262d23f97b98b42225db3dbba6a841b4a",
1899+
strip_prefix = "github.com/cockroachdb/[email protected]20250527172825-a38c80fb488e",
19001900
urls = [
1901-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250523050552-abf8da2b6b97.zip",
1901+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250527172825-a38c80fb488e.zip",
19021902
],
19031903
)
19041904
go_repository(

build/bazelutil/distdir_files.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ DISTDIR_FILES = {
367367
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.19.0.zip": "c4d516bcfe8c07b6fc09b8a9a07a95065b36c2855627cb3514e40c98f872b69e",
368368
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20241215232642-bb51bb14a506.zip": "920068af09e3846d9ebb4e4a7787ff1dd10f3989c5f940ad861b0f6a9f824f6e",
369369
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/metamorphic/com_github_cockroachdb_metamorphic-v0.0.0-20231108215700-4ba948b56895.zip": "28c8cf42192951b69378cf537be5a9a43f2aeb35542908cc4fe5f689505853ea",
370-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250523050552-abf8da2b6b97.zip": "9c1327a1341d78784b000262f7497627d97d0f8e5e669c87a10165044deb6cd9",
370+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250527172825-a38c80fb488e.zip": "b6af4af1463c58e1058577c48aacb50262d23f97b98b42225db3dbba6a841b4a",
371371
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.6.zip": "018eccb5fb9ca52d43ec9eaf213539d01c1f2b94e0e822406ebfb2e9321ef6cf",
372372
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/returncheck/com_github_cockroachdb_returncheck-v0.0.0-20200612231554-92cdbca611dd.zip": "ce92ba4352deec995b1f2eecf16eba7f5d51f5aa245a1c362dfe24c83d31f82b",
373373
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/stress/com_github_cockroachdb_stress-v0.0.0-20220803192808-1806698b1b7b.zip": "3fda531795c600daf25532a4f98be2a1335cd1e5e182c72789bca79f5f69fcc1",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ require (
140140
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
141141
github.com/cockroachdb/gostdlib v1.19.0
142142
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506
143-
github.com/cockroachdb/pebble v0.0.0-20250523050552-abf8da2b6b97
143+
github.com/cockroachdb/pebble v0.0.0-20250527172825-a38c80fb488e
144144
github.com/cockroachdb/redact v1.1.6
145145
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
146146
github.com/cockroachdb/stress v0.0.0-20220803192808-1806698b1b7b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILM
599599
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506/go.mod h1:Mw7HqKr2kdtu6aYGn3tPmAftiP3QPX63LdK/zcariIo=
600600
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895 h1:XANOgPYtvELQ/h4IrmPAohXqe2pWA8Bwhejr3VQoZsA=
601601
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895/go.mod h1:aPd7gM9ov9M8v32Yy5NJrDyOcD8z642dqs+F0CeNXfA=
602-
github.com/cockroachdb/pebble v0.0.0-20250523050552-abf8da2b6b97 h1:e66S+lhckXbKAV8xoPWGLo7s4341nyEijQYTW10YXmk=
603-
github.com/cockroachdb/pebble v0.0.0-20250523050552-abf8da2b6b97/go.mod h1:cnPe7/4+ZaEoSSlr4P3QT2CBbd6fdnP+JQ6On5PEpoE=
602+
github.com/cockroachdb/pebble v0.0.0-20250527172825-a38c80fb488e h1:8KdVMQeaT0BxPO/vzN/FCT2fqkkiyNlaq7hE8C8oQkM=
603+
github.com/cockroachdb/pebble v0.0.0-20250527172825-a38c80fb488e/go.mod h1:cnPe7/4+ZaEoSSlr4P3QT2CBbd6fdnP+JQ6On5PEpoE=
604604
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
605605
github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314=
606606
github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=

pkg/kv/kvserver/raftstorebench/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func writeAmp(m storage.Metrics, payloadBytes int64) WriteAmpStats {
177177
was.WALBytesWritten += int64(m.WAL.BytesWritten)
178178
for i := 0; i < len(m.Levels); i++ {
179179
flushed := m.Levels[i].TableBytesFlushed + m.Levels[i].BlobBytesFlushed // only populated for L0
180-
compacted := m.Levels[i].TableBytesCompacted + m.Levels[i].BlobBytesWritten
180+
compacted := m.Levels[i].TableBytesCompacted + m.Levels[i].BlobBytesCompacted
181181
was.FlushBytesWritten += int64(flushed)
182182
was.CompactionBytesWritten += int64(flushed + compacted)
183183
}

pkg/sql/opt/exec/execbuilder/testdata/select_index_flags

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,41 @@ vectorized: true
357357
missing stats
358358
table: abcd@abcd_pkey
359359
spans: FULL SCAN
360+
361+
# Regression tests for #147363. Statements should not error because the fast path
362+
# picks a plan that does not adhere to hints.
363+
statement ok
364+
CREATE TABLE t147363 (
365+
a INT,
366+
b INT,
367+
c INT,
368+
PRIMARY KEY (a, b),
369+
INDEX i (a, b)
370+
)
371+
372+
statement ok
373+
PREPARE p147363 AS
374+
SELECT * FROM t147363@i WHERE a = $1 AND b = $2
375+
376+
statement ok
377+
EXECUTE p147363(1, 2)
378+
379+
statement ok
380+
DEALLOCATE p147363
381+
382+
statement ok
383+
PREPARE p147363 AS
384+
SELECT * FROM t147363@{FORCE_INVERTED_INDEX} WHERE a = $1 AND b = $2
385+
386+
statement error pgcode XXUUU could not produce a query plan conforming to the FORCE_INVERTED_INDEX hint
387+
EXECUTE p147363(1, 2)
388+
389+
statement ok
390+
DEALLOCATE p147363
391+
392+
statement ok
393+
PREPARE p147363 AS
394+
SELECT * FROM t147363@{FORCE_ZIGZAG} WHERE a = $1 AND b = $2
395+
396+
statement error pgcode XXUUU could not produce a query plan conforming to the FORCE_ZIGZAG hint
397+
EXECUTE p147363(1, 2)

pkg/sql/opt/xform/placeholder_fast_path.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ func (o *Optimizer) TryPlaceholderFastPath() (ok bool, err error) {
8888
return false, nil
8989
}
9090

91+
if scan.Flags.ForceInvertedIndex || scan.Flags.ForceZigzag {
92+
// We don't support inverted or zigzag indexes in the fast path.
93+
return false, nil
94+
}
95+
9196
var constrainedCols opt.ColSet
9297
for i := range sel.Filters {
9398
// Each condition must be an equality between a variable and a constant
@@ -126,6 +131,10 @@ func (o *Optimizer) TryPlaceholderFastPath() (ok bool, err error) {
126131
// Skip inverted and vector indexes.
127132
continue
128133
}
134+
if scan.Flags.ForceIndex && scan.ScanPrivate.Flags.Index != ord {
135+
// If an index is forced, skip all other indexes.
136+
continue
137+
}
129138

130139
if pred, isPartialIndex := tabMeta.PartialIndexPredicate(ord); isPartialIndex {
131140
// We are not equipped to handle partial indexes.

pkg/sql/opt/xform/testdata/placeholder-fast-path/scan

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,33 @@ placeholder-scan t_dec
345345
├── fd: ()-->(1,2)
346346
└── span
347347
└── $1
348+
349+
# Regression tests for #147363. The placeholder fast path should respect index
350+
# flags.
351+
exec-ddl
352+
CREATE TABLE t147363 (
353+
a INT,
354+
b INT,
355+
c INT,
356+
PRIMARY KEY (a, b),
357+
INDEX i (a, b)
358+
)
359+
----
360+
361+
# No fast path is selected because i is not covering.
362+
placeholder-fast-path
363+
SELECT * FROM t147363@i WHERE a = $1 AND b = $2
364+
----
365+
no fast path
366+
367+
# The fast path does not support inverted indexes.
368+
placeholder-fast-path
369+
SELECT * FROM t147363@{FORCE_INVERTED_INDEX} WHERE a = $1 AND b = $2
370+
----
371+
no fast path
372+
373+
# The fast path does not support zig-zag joins.
374+
placeholder-fast-path
375+
SELECT * FROM t147363@{FORCE_ZIGZAG} WHERE a = $1 AND b = $2
376+
----
377+
no fast path

pkg/storage/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ func (m *Metrics) IngestedBytes() uint64 {
13491349
func (m *Metrics) CompactedBytes() (read, written uint64) {
13501350
for _, lm := range m.Metrics.Levels {
13511351
read += lm.TableBytesRead + lm.BlobBytesReadEstimate
1352-
written += lm.TableBytesCompacted + lm.BlobBytesWritten
1352+
written += lm.TableBytesCompacted + lm.BlobBytesCompacted
13531353
}
13541354
return read, written
13551355
}
@@ -1405,7 +1405,7 @@ func (m *Metrics) AsStoreStatsEvent() eventpb.StoreStats {
14051405
BytesIngested: l.TableBytesIngested,
14061406
BytesMoved: l.TableBytesMoved,
14071407
BytesRead: l.TableBytesRead + l.BlobBytesReadEstimate,
1408-
BytesCompacted: l.TableBytesCompacted + l.BlobBytesWritten,
1408+
BytesCompacted: l.TableBytesCompacted + l.BlobBytesCompacted,
14091409
BytesFlushed: l.TableBytesFlushed + l.BlobBytesFlushed,
14101410
TablesCompacted: l.TablesCompacted,
14111411
TablesFlushed: l.TablesFlushed,

pkg/storage/testdata/wal_failover_config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ UnhealthyOperationLatencyThreshold() = (100ms,true)
4848
open flag= envs=(foo,bar) open=foo
4949
----
5050
open error: directory "bar/auxiliary/wals-among-stores" may contain relevant WALs
51+
OPTIONS key: WAL Failover.secondary_dir
5152

5253
# Opening with the "disabled" setting should succeed.
5354

@@ -109,20 +110,24 @@ UnhealthyOperationLatencyThreshold() = (100ms,true)
109110
open flag= envs=(foo) open=foo
110111
----
111112
open error: directory "bax" may contain relevant WALs
113+
OPTIONS key: WAL Failover.secondary_dir
112114

113115
# Try to disable it without setting a prev_path. It should fail
114116
# as well.
115117

116118
open flag=disabled envs=(foo) open=foo
117119
----
118120
open error: directory "bax" may contain relevant WALs
121+
OPTIONS key: WAL Failover.secondary_dir
119122

120123
# Changing the secondary location without specifying prev_path=bax
121124
# should fail.
122125

123126
open flag=path=baz envs=(foo) open=foo
124127
----
125128
open error: directory "bax" may contain relevant WALs
129+
OPTIONS key: WAL Failover.secondary_dir
130+
o.WALFailover.Secondary.Dirname: baz
126131

127132
# Changing the secondary location WITH specifying prev_path=bax
128133
# should succeed.

pkg/util/admission/io_load_listener.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func computeCumStoreCompactionStats(m *pebble.Metrics) cumStoreCompactionStats {
306306
var compactedWriteBytes uint64
307307
baseLevel := -1
308308
for i := range m.Levels {
309-
compactedWriteBytes += m.Levels[i].TableBytesCompacted + m.Levels[i].BlobBytesWritten
309+
compactedWriteBytes += m.Levels[i].TableBytesCompacted + m.Levels[i].BlobBytesCompacted
310310
if i > 0 && m.Levels[i].TablesSize > 0 && baseLevel < 0 {
311311
baseLevel = i
312312
}

0 commit comments

Comments
 (0)