cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.21k stars 3.82k forks source link

sql: v23.1.12: index out of range in maybeIgnoreHiddenColumnsStr #119524

Open cockroach-sentry opened 9 months ago

cockroach-sentry commented 9 months ago

This issue was auto filed by Sentry. It represents a crash or reported error on a live cluster with telemetry enabled.

Sentry Link: https://cockroach-labs.sentry.io/issues/5003119240/?referrer=webhooks_plugin

Panic Message:

conn_executor.go:900: runtime error: slice bounds out of range [:20] with capacity 15
(1) attached stack trace
  -- stack trace:
  | github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn.func1
  |     github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:900
  | [...repeated from below...]
Wraps: (2) attached stack trace
  -- stack trace:
  | github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn.func1
  |     github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:900
  | runtime.gopanic
  |     GOROOT/src/runtime/panic.go:884
  | runtime.goPanicSliceAcap
  |     GOROOT/src/runtime/panic.go:139
  | github.com/cockroachdb/cockroach/pkg/sql.(*copyMachine).maybeIgnoreHiddenColumnsStr
  |     github.com/cockroachdb/cockroach/pkg/sql/copy_from.go:812
  | github.com/cockroachdb/cockroach/pkg/sql.(*copyMachine).readCSVTuple
  |     github.com/cockroachdb/cockroach/pkg/sql/copy_from.go:824
  | github.com/cockroachdb/cockroach/pkg/sql.(*copyMachine).readCSVData
  |     github.com/cockroachdb/cockroach/pkg/sql/copy_from.go:801
  | github.com/cockroachdb/cockroach/pkg/sql.(*copyMachine).processCopyData
  |     github.com/cockroachdb/cockroach/pkg/sql/copy_from.go:644
  | github.com/cockroachdb/cockroach/pkg/sql.(*copyMachine).run
  |     github.com/cockroachdb/cockroach/pkg/sql/copy_from.go:581
  | github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execCopyIn.func9
  |     github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:3166
  | github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execWithProfiling
  |     github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:3083
  | github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execCopyIn
  |     github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:3153
  | github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execCmd
  |     github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2364
  | github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).run
  |     github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2105
  | github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn
  |     github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:902
  | github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*conn).processCommandsAsync.func1
  |     github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:310
  | runtime.goexit
  |     src/runtime/asm_arm64.s:1172
Wraps: (3) runtime error: slice bounds out of range [:20] with capacity 15
Error types: (1) *withstack.withStack (2) *withstack.withStack (3) runtime.boundsError
-- report composition:
runtime.boundsError
conn_executor.go:900: *withstack.withStack (top exception)
conn_executor.go:900: *withstack.withStack (1)
(check the extra data payloads)
Stacktrace (expand for inline code snippets): [src/runtime/asm_arm64.s#L1171-L1173](src/runtime/asm_arm64.s#L1171-L1173) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/pgwire/conn.go#L309-L311](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/pgwire/conn.go#L309-L311) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L901-L903](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L901-L903) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L2104-L2106](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L2104-L2106) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L2363-L2365](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L2363-L2365) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L3152-L3154](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L3152-L3154) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor_exec.go#L3082-L3084](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor_exec.go#L3082-L3084) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L3165-L3167](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L3165-L3167) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L580-L582](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L580-L582) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L643-L645](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L643-L645) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L800-L802](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L800-L802) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L823-L825](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L823-L825) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L811-L813](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/copy_from.go#L811-L813) [GOROOT/src/runtime/panic.go#L138-L140](GOROOT/src/runtime/panic.go#L138-L140) [GOROOT/src/runtime/panic.go#L883-L885](GOROOT/src/runtime/panic.go#L883-L885) [https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L899-L901](https://github.com/cockroachdb/cockroach/blob/d7e9824b4cd6ebf7a8548156f2a772ae6648257d/pkg/sql/conn_executor.go#L899-L901)
src/runtime/asm_arm64.s in runtime.goexit at line 1172
pkg/sql/pgwire/conn.go in pkg/sql/pgwire.(*conn).processCommandsAsync.func1 at line 310
pkg/sql/conn_executor.go in pkg/sql.(*Server).ServeConn at line 902
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).run at line 2105
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).execCmd at line 2364
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).execCopyIn at line 3153
pkg/sql/conn_executor_exec.go in pkg/sql.(*connExecutor).execWithProfiling at line 3083
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).execCopyIn.func9 at line 3166
pkg/sql/copy_from.go in pkg/sql.(*copyMachine).run at line 581
pkg/sql/copy_from.go in pkg/sql.(*copyMachine).processCopyData at line 644
pkg/sql/copy_from.go in pkg/sql.(*copyMachine).readCSVData at line 801
pkg/sql/copy_from.go in pkg/sql.(*copyMachine).readCSVTuple at line 824
pkg/sql/copy_from.go in pkg/sql.(*copyMachine).maybeIgnoreHiddenColumnsStr at line 812
GOROOT/src/runtime/panic.go in runtime.goPanicSliceAcap at line 139
GOROOT/src/runtime/panic.go in runtime.gopanic at line 884
pkg/sql/conn_executor.go in pkg/sql.(*Server).ServeConn.func1 at line 900

Tags

Tag Value
Command server
Environment v23.1.12
Go Version go1.19.13
Platform linux arm64
Distribution CCL
Cockroach Release v23.1.12
Cockroach SHA d7e9824b4cd6ebf7a8548156f2a772ae6648257d
# of CPUs 8
# of Goroutines 892

Jira issue: CRDB-36269

DrewKimball commented 7 months ago

Repro:

root@localhost:26257/defaultdb> set expect_and_ignore_not_visible_columns_in_copy=true;
SET

Time: 1ms total (execution 1ms / network 0ms)
root@localhost:26257/defaultdb> create table t (x int primary key, y int, index foo ((x + y)));
CREATE TABLE

Time: 26ms total (execution 26ms / network 0ms)
root@localhost:26257/defaultdb> alter table t add column z int not visible;
ALTER TABLE

Time: 259ms total (execution 259ms / network 0ms)
root@localhost:26257/defaultdb> copy t from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself, or an EOF signal.
>> 1    2       3
>> \.

Result (server-side):

* ERROR: a panic has occurred!
* runtime error: slice bounds out of range [4:3]
* (1) attached stack trace
*   -- stack trace:
*   | github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn.func1
*   |   github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:965
*   | [...repeated from below...]
* Wraps: (2) attached stack trace
*   -- stack trace:
*   | github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn.func1
*   |   github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:965
*   | runtime.gopanic
*   |   GOROOT/src/runtime/panic.go:770
*   | runtime.goPanicSliceB
*   |   GOROOT/src/runtime/panic.go:154
*   | github.com/cockroachdb/cockroach/pkg/sql.(*copyMachine).maybeIgnoreHiddenColumnsBytes
*   |   github.com/cockroachdb/cockroach/pkg/sql/copy_from.go:1230
*   | github.com/cockroachdb/cockroach/pkg/sql.(*copyMachine).readTextTuple
*   |   github.com/cockroachdb/cockroach/pkg/sql/copy_from.go:1240
*   | github.com/cockroachdb/cockroach/pkg/sql.(*copyMachine).readTextData
DrewKimball commented 7 months ago

The issue is that while we check that the supplied rows match up to visible + hidden columns, some columns are not either of those things, which leads to the indexes in expectedHiddenColumnIdxs being out of range for the input rows. https://github.com/cockroachdb/cockroach/blob/d45a65e08d45383aade2bcffdcdbe72a0cc279b1/pkg/sql/copy_from.go#L832-L835 In the case of the repro above, the expression index adds an inaccessible crdb_internal_idx_expr column, which offsets the added hidden column by one.