Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: create materalized view can cause panic #76710

Closed
Azhng opened this issue Feb 16, 2022 · 4 comments · Fixed by #105324
Closed

sql: create materalized view can cause panic #76710

Azhng opened this issue Feb 16, 2022 · 4 comments · Fixed by #105324
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@Azhng
Copy link
Contributor

Azhng commented Feb 16, 2022

Describe the problem

Executing the following statement can cause a runtime panic:

CREATE MATERIALIZED VIEW t76710_2 AS SELECT fingerprint_id FROM crdb_internal.cluster_statement_statistics;

To Reproduce

This can be reprodued from master.

Expected behavior

Do not panic.

Additional data / screenshots

*
* ERROR: a panic has occurred!
* internal-planner.root.materializedViewBackfill: unexpected 20480 leftover bytes
* (1) attached stack trace
*   -- stack trace:
*   | runtime.gopanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038
*   | github.com/cockroachdb/cockroach/pkg/util/log/logcrash.ReportOrPanic
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/log/logcrash/crash_reporting.go:376
*   | github.com/cockroachdb/cockroach/pkg/util/mon.(*BytesMonitor).doStop
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/mon/bytes_usage.go:414
*   | github.com/cockroachdb/cockroach/pkg/util/mon.(*BytesMonitor).Stop
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/mon/bytes_usage.go:394
*   | github.com/cockroachdb/cockroach/pkg/sql.newInternalPlanner.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/planner.go:415
*   | runtime.gopanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:58
*   | runtime.gopanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:58
*   | runtime.gopanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038
*   | runtime.panicmem
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:221
*   | runtime.sigpanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/signal_unix.go:735
*   | github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats.(*PersistedSQLStats).ComputeAggregatedTs
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats/flush.go:244
*   | github.com/cockroachdb/cockroach/pkg/sql.glob..func33
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/crdb_internal.go:5114
*   | github.com/cockroachdb/cockroach/pkg/sql.(*virtualDefEntry).getPlanInfo.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:525
*   | github.com/cockroachdb/cockroach/pkg/sql.constructVirtualScan.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/exec_factory_util.go:236
*   | github.com/cockroachdb/cockroach/pkg/sql.(*delayedNode).startExec
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/delayed.go:50
*   | github.com/cockroachdb/cockroach/pkg/sql.startExec.func2
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan.go:516
*   | github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:112
*   | github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:296
*   | github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visit
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:79
*   | github.com/cockroachdb/cockroach/pkg/sql.walkPlan
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:43
*   | github.com/cockroachdb/cockroach/pkg/sql.startExec
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan.go:519
*   | github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Start
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:146
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*Columnarizer).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/columnarizer.go:158
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*SerialUnorderedSynchronizer).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/serial_unordered_synchronizer.go:71
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*hashAggregator).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/hash_aggregator.go:245
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*diskSpillerBase).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/disk_spiller.go:187
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputHelper).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:290
* Wraps: (2) attached stack trace
*   -- stack trace:
*   | github.com/cockroachdb/cockroach/pkg/util/log/logcrash.ReportOrPanic
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/log/logcrash/crash_reporting.go:374
*   | github.com/cockroachdb/cockroach/pkg/util/mon.(*BytesMonitor).doStop
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/mon/bytes_usage.go:414
*   | github.com/cockroachdb/cockroach/pkg/util/mon.(*BytesMonitor).Stop
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/mon/bytes_usage.go:394
*   | github.com/cockroachdb/cockroach/pkg/sql.newInternalPlanner.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/planner.go:415
*   | runtime.gopanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:58
*   | runtime.gopanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:58
*   | runtime.gopanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038
*   | runtime.panicmem
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:221
*   | runtime.sigpanic
*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/signal_unix.go:735
*   | github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats.(*PersistedSQLStats).ComputeAggregatedTs
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats/flush.go:244
*   | github.com/cockroachdb/cockroach/pkg/sql.glob..func33
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/crdb_internal.go:5114
*   | github.com/cockroachdb/cockroach/pkg/sql.(*virtualDefEntry).getPlanInfo.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:525
*   | github.com/cockroachdb/cockroach/pkg/sql.constructVirtualScan.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/exec_factory_util.go:236
*   | github.com/cockroachdb/cockroach/pkg/sql.(*delayedNode).startExec
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/delayed.go:50
*   | github.com/cockroachdb/cockroach/pkg/sql.startExec.func2
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan.go:516
*   | github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal.func1
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:112
*   | github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:296
*   | github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visit
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:79
*   | github.com/cockroachdb/cockroach/pkg/sql.walkPlan
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:43
*   | github.com/cockroachdb/cockroach/pkg/sql.startExec
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan.go:519
*   | github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Start
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:146
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*Columnarizer).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/columnarizer.go:158
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*SerialUnorderedSynchronizer).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/serial_unordered_synchronizer.go:71
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*hashAggregator).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/hash_aggregator.go:245
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*diskSpillerBase).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/disk_spiller.go:187
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputHelper).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:290
*   | github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369
*   | github.com/cockroachdb/cockroach/pkg/sql/colexec.(*hashAggregator).Init
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/hash_aggregator.go:245
* Wraps: (3) internal-planner.root.materializedViewBackfill: unexpected 20480 leftover bytes
* Error types: (1) *withstack.withStack (2) *withstack.withStack (3) *errutil.leafError
*
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
	panic: internal-planner.root.materializedViewBackfill: unexpected 20480 leftover bytes [recovered]
	panic: internal-planner.root.materializedViewBackfill: unexpected 20480 leftover bytes
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x5dac7f4]

goroutine 3679 [running]:
github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).Recover(0xc0011d86c0, {0x9b3aec8, 0xc00276f500})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:251 +0x94
panic({0x83b6dc0, 0xc000728198})
	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038 +0x215
github.com/cockroachdb/cockroach/pkg/util/log/logcrash.ReportOrPanic({0x9b3aec8, 0xc002e017a0}, 0xc00122e000, {0x87aa608, 0x40782ef}, {0xc0021c7df0, 0x8653540, 0xc002c202e0})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/log/logcrash/crash_reporting.go:376 +0x1bd
github.com/cockroachdb/cockroach/pkg/util/mon.(*BytesMonitor).doStop(0xc003b888c0, {0x9b3aec8, 0xc002e017a0}, 0x1)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/mon/bytes_usage.go:414 +0x274
github.com/cockroachdb/cockroach/pkg/util/mon.(*BytesMonitor).Stop(...)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/mon/bytes_usage.go:394
github.com/cockroachdb/cockroach/pkg/sql.newInternalPlanner.func1()
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/planner.go:415 +0x5f
panic({0x8084d60, 0xc8c56b0})
	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038 +0x215
github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1()
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:58 +0x3bb
panic({0x8084d60, 0xc8c56b0})
	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038 +0x215
github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1()
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:58 +0x3bb
panic({0x8084d60, 0xc8c56b0})
	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038 +0x215
github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats.(*PersistedSQLStats).ComputeAggregatedTs(0xc0021fa000)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats/flush.go:244 +0x14
github.com/cockroachdb/cockroach/pkg/sql.glob..func33({0x9b3aec8, 0xc0027299b0}, 0xc003c90000, {0xc0027299b0, 0x80cc820}, 0x872e6c5)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/crdb_internal.go:5114 +0x1b8
github.com/cockroachdb/cockroach/pkg/sql.(*virtualDefEntry).getPlanInfo.func1({0x9b3aec8, 0xc0027299b0}, 0xc003c90000, {0x872e6c5, 0x30})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:525 +0x258
github.com/cockroachdb/cockroach/pkg/sql.constructVirtualScan.func1({0x9b3aec8, 0xc0027299b0}, 0x1)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/exec_factory_util.go:236 +0x34
github.com/cockroachdb/cockroach/pkg/sql.(*delayedNode).startExec(0xc003d89950, {{0x9b3aec8, 0xc0027299b0}, 0xc003d90f00, 0xc003c90000})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/delayed.go:50 +0x65
github.com/cockroachdb/cockroach/pkg/sql.startExec.func2({0xc0042bca58, 0x4010d30}, {0x9b3c5c0, 0xc003d89950})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan.go:516 +0x147
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal.func1()
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:112 +0x3e
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal(0xc0042bcb68, {0x9b3c5c0, 0xc003d89950}, {0x874a84d, 0xd})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:296 +0x1469
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visit(0xc0042bcb68, {0x9b3c5c0, 0xc003d89950})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:79 +0xf7
github.com/cockroachdb/cockroach/pkg/sql.walkPlan(...)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/walk.go:43
github.com/cockroachdb/cockroach/pkg/sql.startExec({{0x9b3aec8, 0xc0027299b0}, 0xc003d90f00, 0xc003c90000}, {0x9b3c5c0, 0xc003d89950})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan.go:519 +0x125
github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Start(0xc003ef0600, {0x9b3aec8, 0xc0027299b0})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:146 +0x87
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*Columnarizer).Init(0xc003fd6400, {0x9b3aec8, 0xc0027299b0})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/columnarizer.go:158 +0xd4
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*SerialUnorderedSynchronizer).Init(0xc003fac3c0, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/serial_unordered_synchronizer.go:71 +0x12e
github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init(0xc003fac400, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369 +0x48
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*hashAggregator).Init(0xc00320d400, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/hash_aggregator.go:245 +0x65
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*diskSpillerBase).Init(0xc001914090, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/disk_spiller.go:187 +0x50
github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init(0xc003fd4f00, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369 +0x48
github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputHelper).Init(0xc003b89a40, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:290 +0x4f
github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init(0xc0027cf6e0, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369 +0x48
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*hashAggregator).Init(0xc000fbe500, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/hash_aggregator.go:245 +0x65
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*diskSpillerBase).Init(0xc001914a20, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/disk_spiller.go:187 +0x50
github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init(0xc003fd5090, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369 +0x48
github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputHelper).Init(0xc00401e280, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:290 +0x4f
github.com/cockroachdb/cockroach/pkg/sql/colexecop.(*OneInputInitCloserHelper).Init(0xc0027cfb60, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecop/operator.go:369 +0x48
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*Materializer).Start.func1()
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/materializer.go:248 +0x34
github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError(0xc0019a0000)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:91 +0x62
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*Materializer).Start(0xc003f30380, {0x9b3aec8, 0xc002729980})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/materializer.go:247 +0x78
github.com/cockroachdb/cockroach/pkg/sql/rowexec.(*bulkRowWriter).Start(0xc00405e000, {0x9b3ae20, 0xc003fac300})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowexec/bulk_row_writer.go:79 +0x72
github.com/cockroachdb/cockroach/pkg/sql/colflow.(*FlowCoordinator).Start.func1()
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colflow/flow_coordinator.go:120 +0x34
github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError(0x8727208)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:91 +0x62
github.com/cockroachdb/cockroach/pkg/sql/colflow.(*FlowCoordinator).Start(0xc003241d00, {0x9b3ae20, 0xc003fac300})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colflow/flow_coordinator.go:119 +0x6b
github.com/cockroachdb/cockroach/pkg/sql/execinfra.(*ProcessorBaseNoHelper).Run(0xc003241d00, {0x9b3ae20, 0xc003fac300})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:732 +0x3a
github.com/cockroachdb/cockroach/pkg/sql/flowinfra.(*FlowBase).Run(0xc003ac3860, {0x9b3ae20, 0xc003fac300}, 0xc003241d00)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/flowinfra/flow.go:461 +0x258
github.com/cockroachdb/cockroach/pkg/sql/colflow.(*vectorizedFlow).Run(0xc003d91200, {0x9b3ae20, 0xc003fac300}, 0xc003b9e420)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/colflow/vectorized_flow.go:246 +0x205
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).Run(0xc0011e8400, 0xc000bd8f00, 0xc003b9e420, 0xc003fe2000, 0xc0026aca80, 0xc003d91200, 0x0)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:574 +0xc51
github.com/cockroachdb/cockroach/pkg/sql.PlanAndRunCTAS({_, _}, _, _, _, _, {{_, _}, _}, {0x0, ...}, ...)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_plan_ctas.go:53 +0x40e
github.com/cockroachdb/cockroach/pkg/sql.(*SchemaChanger).backfillQueryIntoTable.func1.3()
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:351 +0x3d2
github.com/cockroachdb/cockroach/pkg/sql.(*planner).runWithOptions(0xc0029f3140, {0x20, 0xc0}, 0x0)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/resolver.go:65 +0x105
github.com/cockroachdb/cockroach/pkg/sql.(*SchemaChanger).backfillQueryIntoTable.func1({0x9b3aec8, 0xc00231fa40}, 0xc003b9e420)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:323 +0x6d1
github.com/cockroachdb/cockroach/pkg/kv.runTxn.func1({0x9b3aec8, 0xc00231fa40}, 0x9bb41d8)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/kv/db.go:883 +0x27
github.com/cockroachdb/cockroach/pkg/kv.(*Txn).exec(0xc003b9e420, {0x9b3aec8, 0xc00231fa40}, 0xc0021caa30)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/kv/txn.go:972 +0xb7
github.com/cockroachdb/cockroach/pkg/kv.runTxn({0x9b3aec8, 0xc00231fa40}, 0xc0011d8e10, 0x100000000)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/kv/db.go:882 +0x5a
github.com/cockroachdb/cockroach/pkg/kv.(*DB).Txn(0xc0013ef860, {0x9b3aec8, 0xc00231fa40}, 0x0)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/kv/db.go:864 +0x85
github.com/cockroachdb/cockroach/pkg/sql.(*SchemaChanger).backfillQueryIntoTable(0x1, {0x9b3aec8, 0xc00231fa40}, {0x9c5b928, 0xc00320c000}, {0xc00105ac00, 0x3c}, {0x16d462e2bd1cbdb0, 0x0, 0x0}, ...)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:259 +0x17c
github.com/cockroachdb/cockroach/pkg/sql.(*SchemaChanger).maybeBackfillMaterializedView(0xc00320c000, {0x9b3aec8, 0xc00231fa40}, {0x9c5b928, 0xc00320c000})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:388 +0x192
github.com/cockroachdb/cockroach/pkg/sql.(*SchemaChanger).exec(0xc0009d1b20, {0x9b3aec8, 0xc0035b18c0})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:675 +0x79d
github.com/cockroachdb/cockroach/pkg/sql.schemaChangeResumer.Resume.func1(0x70, 0x0, 0x0)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:2189 +0x4c8
github.com/cockroachdb/cockroach/pkg/sql.schemaChangeResumer.Resume({0xc003ef5658}, {0x9b3aec8, 0xc0035b18c0}, {0x84c3780, 0xc0024423c8})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:2320 +0x76e
github.com/cockroachdb/cockroach/pkg/jobs.(*Registry).stepThroughStateMachine.func2(0x9b3aec8, {0x9abca70, 0xc0004dac40}, {0x9b3aec8, 0xc0035b18c0}, {0x84c3780, 0xc0024423c8}, 0xc0021cb928)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/jobs/registry.go:1124 +0xba
github.com/cockroachdb/cockroach/pkg/jobs.(*Registry).stepThroughStateMachine(0xc001348500, {0x9b3aec8, 0xc00349ba70}, {0x84c3780, 0xc0024423c8}, {0x9abca70, 0xc0004dac40}, 0xc00340b680, {0xc003fc4d70, 0x7}, ...)
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/jobs/registry.go:1125 +0x6d7
github.com/cockroachdb/cockroach/pkg/jobs.(*Registry).runJob(0xc001348500, {0x9b3ae20, 0xc00306c580}, {0x9abca70, 0xc0004dac40}, 0xc00340b680, {0xc003fc4d70, 0x7}, {0xc0013ef0f8, 0x16})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/jobs/adopt.go:402 +0x54f
github.com/cockroachdb/cockroach/pkg/jobs.(*Registry).resumeJob.func1({0xc002a25800, 0xc001d80810})
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/jobs/adopt.go:323 +0xfa
github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx.func2()
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:494 +0x16f
created by github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx
	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:483 +0x445
Time: 0h:00m:06s
FAIL: 2

Environment:

  • CockroachDB version: master@892c6407d623e675ce36777a16b7ebb0d52b03da

Epic: CRDB-13625
Jira issue: CRDB-13244

@Azhng Azhng added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team labels Feb 16, 2022
@Azhng
Copy link
Contributor Author

Azhng commented Feb 16, 2022

Note: the underlying crdb_internal.statement_statistics is a virtual view that unions a system table (system.statement_statistics) and a virtual table (crdb_internal.cluster_statement_statistics).

When directly creating the materialized view on the system table alone, the ERROR unimplemented: views do not currently support * expression is returned.

@Azhng Azhng added A-sql-observability Related to observability of the SQL layer T-sql-observability and removed T-sql-queries SQL Queries Team labels Feb 16, 2022
@ajwerner
Copy link
Contributor

I think the observation which is legit is we should catch this panic and turn it into an error. Also, we shouldn't have this panic.

@Azhng
Copy link
Contributor Author

Azhng commented Feb 16, 2022

This few lines look sus.

*   | 	/usr/local/Cellar/go/1.17.2/libexec/src/runtime/signal_unix.go:735
*   | github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats.(*PersistedSQLStats).ComputeAggregatedTs
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats/flush.go:244
*   | github.com/cockroachdb/cockroach/pkg/sql.glob..func33
*   | 	/Users/azhng/go/src/github.com/cockroachdb/cockroach/pkg/sql/crdb_internal.go:5114

Looking at this line, it might be a null pointer error.

curAggTs := s.ComputeAggregatedTs()

My hypothesis here is that when an InternalExecutor executes an explicit transaction that reads from this virtual table, this panic can happen 🤔

@Azhng Azhng added the T-sql-queries SQL Queries Team label Feb 16, 2022
@rafiss
Copy link
Collaborator

rafiss commented Feb 16, 2022

I'm guessing this will be caused by the same underlying problem as #73498 and #73249 and #65516

Azhng added a commit to Azhng/cockroach that referenced this issue Feb 17, 2022
…able

Previously, a null pointer error in
crdb_internal.cluster_statement_statistics can cause a runtime panic
when it is read by internal executor.

This commit fixes the null pointer error by properly propagating state
in internalExtendedEvalCtx().

Partially resolves cockroachdb#76710

Release note (bug fix): creating materialized view on
crdb_internal.cluster_statement_statistics no longer cause panic.
@maryliag maryliag removed A-sql-observability Related to observability of the SQL layer T-sql-observability labels Mar 7, 2022
@craig craig bot closed this as completed in 71228e5 Jun 22, 2023
@mgartner mgartner moved this to Done in SQL Queries Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team
Projects
Archived in project
4 participants