-
Notifications
You must be signed in to change notification settings - Fork 4.1k
colexec: wrong datum type with Bytes physical canonical type family #57165
Description
Describe the problem
I have an audit_logs table with an id int, created_at timestamp and data jsonb (along with other columns). I'm trying to remove a field from the data column, using data - 'auth_id':
select data - 'auth_id' from audit_logs order by id limit 1;
This works. But, if I switch the order by id limit 1 to order by created_at limit 1, it crashes:
select data - 'auth_id' from audit_logs order by created_at limit 1;
ERROR: XX000: internal error: expected *DString, found *tree.DBytes
DETAIL: stack trace:
/go/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/datum.go:1125: MustBeDString()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/eval.go:1100: func64()
/go/src/github.com/cockroachdb/cockroach/pkg/col/coldataext/datum_vec.go:61: BinFn()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/proj_const_right_ops.eg.go:8644: Next()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/simple_project.go:124: Next()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/limit.go:53: Next()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/materializer.go:216: next()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/materializer.go:241: nextAdapter()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexecbase/colexecerror/error.go:93: CatchVectorizedRuntimeError()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/materializer.go:247: Next()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/base.go:170: Run()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:775: Run()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/flowinfra/flow.go:392: Run()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:422: Run()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:991: PlanAndRun()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1001: execWithDistSQLEngine()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:872: dispatchToExecutionEngine()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:639: execStmtInOpenState()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:114: execStmt()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1465: func1()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1467: execCmd()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1391: run()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:508: ServeConn()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:626: func1()
/usr/local/go/src/runtime/asm_amd64.s:1357: goexit()HINT: You have encountered an unexpected error.Please check the public issue tracker to check whether this problem is
already tracked. If you cannot find it there, please report the error
with details by creating a new issue.If you would rather not post publicly, please contact us directly
using the support form.We appreciate your feedback.LOCATION: MustBeDString, datum.go:1125
Time: 8.550 ms
Both order by created_at limit 1 and order by id limit 1 return the same row (there's no duplicate at that created_at). select data from audit_logs order by created_at limit 1 works.
But it gets weirder.
If I do: data::text::jsonb - 'auth_id it works.
Further, if I do select data - 'auth_id' from audit_logs order by id limit 999 it works, but if I do limit 1000 it crashes again. If I do where id > 1 limit 999 it works, but where id > 1 limit 1000 it crashes.
This tells me that there isn't a problem with individual rows. Both the order by id limit 1 and order by created_at limit 1 touch the same row. Similarly, order by id limit 1000 crashes, but where id > 1 order by limit 999 doesn't - even though they both touch the same 1000th row.
It behaves the same if I try to use CTEs or sub-selects to wrap the rows.
select jsonb_object_keys(data) from audit_logs; works as does select data || '{"test": 1}' from audit_logs;
Version:
CockroachDB CCL v20.2.0 (x86_64-unknown-linux-gnu, built 2020/11/09 16:01:45, go1.13.14), running on Ubuntu 20.04.