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
29.97k stars 3.79k forks source link

sql: empty tuple comparison causes "empty end boundary must be inclusive" #93408

Open SteveLeungYL opened 1 year ago

SteveLeungYL commented 1 year ago

Describe the problem

The latest version of the CockroachDB (ec83b9eba5f2) shows Internal Error when executing the following query:

SET testing_optimizer_disable_rule_probability = 1.0;
create table v0 ();
SELECT * FROM v0 WHERE () < ();

To Reproduce

Here is the detail steps to reproduce the bug.

  1. In system Ubuntu 20.04, download the CockroachDB source code from the github source.
  2. Use the latest version of the CockroachDB code (tested version: ec83b9eba5f2b)
  3. Directly make install in the root repository folder.
  4. Run ./cockroach demo, and then paste the PoC query to the cockroach cli environment.
  5. Observe the Internal Error and log the stack information.

Expected behavior The SELECT statement should be executed correctly and return empty result.

Additional data / screenshots

Here is the outputted stack trace:

ERROR: internal error: an empty end boundary must be inclusive
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/opt/constraint/span.go:140: Init()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/constraint_builder.go:421: buildConstraintForTupleInequality()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/constraint_builder.go:580: buildConstraints()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/logical_props_builder.go:1534: buildFiltersItemProps()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/expr.og.go:9270: PopulateProps()
github.com/cockroachdb/cockroach/pkg/sql/opt/norm/factory.og.go:12470: ConstructFiltersItem()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1190: buildWhere()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1061: buildSelectClause()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1006: buildSelectStmtWithoutParens()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:975: func1()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/with.go:117: processWiths()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:974: buildSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:305: buildStmt()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:252: buildStmtAtRoot()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:226: Build()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:570: buildExecMemo()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:237: makeOptimizerPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1518: makeExecPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1125: dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:737: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:130: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2513: execWithProfiling()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:129: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1955: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1960: execCmd()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1878: run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:834: ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:728: func1()
runtime/asm_amd64.s:1594: goexit()

HINT: You have encountered an unexpected error.

Environment:

cockroach version details:
Build Tag:        v23.1.0-alpha.00000000-1124-gec83b9eba5-dirty
Build Time:       2022/12/12 01:12:12
Distribution:     CCL
Platform:         linux amd64 (x86_64-linux-gnu)
Go Version:       go1.19
C Compiler:       gcc 9.4.0
Build Commit ID:  ec83b9eba5f2b09f9fc8610c8a976e49854d212d
Build Type:       development
(use './cockroach version --build-tag' to display only the build tag)

Additional context

The crashing problem may not happen in the real-world application, since it requires the specific setup: SET testing_optimizer_disable_rule_probability = 1.0;, which is a developer option used to control the query optimization. However, having an Internal Error is still unexpected from the resulted behavior. Therefore, this problem is reported here.

The Internal Error problem is reproducible on version v22.2.0 Production Releases.

Jira issue: CRDB-22318

blathers-crl[bot] commented 1 year ago

Hello, I am Blathers. I am here to help you get the issue triaged.

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

I have CC'd a few people who may be able to assist you:

If we have not gotten back to your issue within a few business days, you can try the following:

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

mgartner commented 1 year ago

This might be related to #94087.