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: Internal Executor does not work properly with Virtual Index #71414

Closed
jackcwu opened this issue Oct 11, 2021 · 3 comments · Fixed by #73635
Closed

sql: Internal Executor does not work properly with Virtual Index #71414

jackcwu opened this issue Oct 11, 2021 · 3 comments · Fixed by #73635
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. S-2-temp-unavailability Temp crashes or other availability problems. Can be worked around or resolved by restarting. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@jackcwu
Copy link
Contributor

jackcwu commented Oct 11, 2021

Problem
When including the INDEX field when defining virtual schema tables in crdb_internal.go and calling it through a built-in, it causes a panic

To Reproduce

  1. Apply this diff
diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go
index 28502a8986..0ab8504bd0 100644
--- a/pkg/sql/crdb_internal.go
+++ b/pkg/sql/crdb_internal.go
@@ -2243,7 +2243,8 @@ CREATE TABLE crdb_internal.create_type_statements (
   descriptor_id      INT,
   descriptor_name    STRING,
   create_statement   STRING,
-  enum_members       STRING[] -- populated only for ENUM types
+  enum_members       STRING[], -- populated only for ENUM types
+INDEX (descriptor_id)
 )
 `,
     populate: func(ctx context.Context, p *planner, db catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
  1. start a server
  2. run create type greeting as enum ('hi');
  3. run SHOW CREATE ALL TYPES;

Expected behavior
This should not panic since the enums are being properly populated

Additional data / screenshots

  • ERROR: [n1,client=127.0.0.1:64058,hostssl,user=demo,intExec=crdb_internal.show_create_all_types] a panic has occurred!
  • runtime error: index out of range [0] with length 0
  • (1) attached stack trace
  • -- stack trace:
  • | runtime.gopanic
  • | /usr/local/opt/go/libexec/src/runtime/panic.go:1038
  • | runtime.goPanicIndex
  • | /usr/local/opt/go/libexec/src/runtime/panic.go:90
  • | github.com/cockroachdb/cockroach/pkg/sql.virtualSchemaTable.getIndex
  • | /Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:220
  • | github.com/cockroachdb/cockroach/pkg/sql.(*virtualDefEntry).makeConstrainedRowsGenerator.func1
  • | /Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:628
  • | github.com/cockroachdb/cockroach/pkg/sql.setupGenerator.func3
  • | /Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_table.go:120
  • | github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx.func2
  • | /Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:491
  • | runtime.goexit
  • | /usr/local/opt/go/libexec/src/runtime/asm_amd64.s:1581
  • Wraps: (2) runtime error: index out of range [0] with length 0
  • Error types: (1) *withstack.withStack (2) runtime.boundsError

panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0

goroutine 7396 [running]:
github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).Recover(0xc0009ec090, {0x99ef238, 0xc001288740})
/Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:254 +0xaa
panic({0x80e4e40, 0xc001568360})
/usr/local/opt/go/libexec/src/runtime/panic.go:1038 +0x215
github.com/cockroachdb/cockroach/pkg/sql.virtualSchemaTable.getIndex(...)
/Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:220
github.com/cockroachdb/cockroach/pkg/sql.(*virtualDefEntry).makeConstrainedRowsGenerator.func1({0x99555e0, 0xc000674400})
/Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:628 +0x7f9
github.com/cockroachdb/cockroach/pkg/sql.setupGenerator.func3({0x99ef238, 0xc001288740})
/Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/sql/virtual_table.go:120 +0x130
github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx.func2()
/Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:491 +0x12a
created by github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx
/Users/jackwu/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:481 +0x445

Environment:

  • CockroachDB version [e.g. 2.0.x]
  • Server OS: [e.g. Linux/Distrib]
  • Client app [e.g. cockroach sql, JDBC, ...]

Additional context
What was the impact?

Add any other context about the problem here.

@jackcwu jackcwu added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Oct 11, 2021
@jackcwu jackcwu changed the title Internal Executor does not work properly with Virtual Indexes Internal Executor does not work properly with Virtual Indexe Oct 11, 2021
@jackcwu jackcwu changed the title Internal Executor does not work properly with Virtual Indexe Internal Executor does not work properly with Virtual Index Oct 11, 2021
@rafiss rafiss changed the title Internal Executor does not work properly with Virtual Index sql: Internal Executor does not work properly with Virtual Index Oct 11, 2021
@rafiss rafiss added the E-starter Might be suitable for a starter project for new employees or team members. label Dec 6, 2021
@rafiss rafiss added S-2-temp-unavailability Temp crashes or other availability problems. Can be worked around or resolved by restarting. and removed E-starter Might be suitable for a starter project for new employees or team members. labels Dec 7, 2021
@otan
Copy link
Contributor

otan commented Dec 9, 2021

this isn't a bug - this is an unfinished implementation!

you need to also implement how a index works in this case:

indexes []virtualIndex

@otan otan closed this as completed Dec 9, 2021
@rafiss
Copy link
Collaborator

rafiss commented Dec 9, 2021

looks like this actually was always broken since 0bcddba. (the INDEX was added without being implemented. there probably should be some validation that disallows that...)

confirmed that it's broken in 21.1, so i'm actually going to re-open this and fix.

root@:26257/defaultdb> create type mood as enum ('meh');
CREATE TYPE

root@:26257/defaultdb> select * from crdb_internal.create_type_statements where descriptor_id=123;
ERROR: driver: bad connection
warning: connection lost!

@rafiss rafiss reopened this Dec 9, 2021
@otan
Copy link
Contributor

otan commented Dec 9, 2021

ooof

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. S-2-temp-unavailability Temp crashes or other availability problems. Can be worked around or resolved by restarting. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants