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 error: estimated row count must be non-zero #40456

Closed
maddyblue opened this issue Sep 4, 2019 · 0 comments · Fixed by #40472
Closed

sql: internal error: estimated row count must be non-zero #40456

maddyblue opened this issue Sep 4, 2019 · 0 comments · Fixed by #40472
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sqlsmith

Comments

@maddyblue
Copy link
Contributor

CREATE TABLE IF NOT EXISTS tab_orig AS
	SELECT substring(NULL, NULL, NULL)::UUID AS _uuid;

SELECT
	NULL
FROM
	tab_orig AS tab_3129
WHERE
	NOT EXISTS(SELECT tab_3129._uuid);
pq: internal error: estimated row count must be non-zero
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/statistics_builder.go:2279: finalizeFromCardinality()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/statistics_builder.go:735: buildProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/logical_props_builder.go:323: buildProjectProps()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/expr.og.go:15154: MemoizeProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/norm/factory.og.go:1555: ConstructProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/norm/factory.og.go:1284: ConstructProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/project.go:58: constructProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/project.go:30: constructProjectForScope()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:851: buildSelectClause()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:757: buildSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:241: buildStmt()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:185: Build()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:419: buildExecMemo()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:161: makeOptimizerPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:734: makeExecPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:616: dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:417: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:98: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1238: execCmd()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1167: run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:444: ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:584: func1()
runtime/asm_amd64.s:1337: goexit()
@maddyblue maddyblue added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sqlsmith labels Sep 4, 2019
rytaft added a commit to rytaft/cockroach that referenced this issue Sep 4, 2019
This commit fixes the calculation of the cardinality logical property
for semi and anti joins to account for the filter conditions as well as
the cardinality of the right hand side.

It also updates the stats estimate to ensure that the row count of semi
and anti joins is not zero unless the cardinality is zero.

Fixes cockroachdb#40456

Release note: None
craig bot pushed a commit that referenced this issue Sep 5, 2019
40417: sql: Remove unnecessary constraints check in show create r=rohany a=rohany

The show create table function would not display a zone configuration
if the constraints list was empty. However, this isn't a valid check
because the constraints list could be empty but other fields set.

Release note: None

40441: storage: assert zero HardState.Commit on replica creation r=nvanbenschoten a=nvanbenschoten

An uninitialized replica should never have a commit index in its
HardState. And yet, we observed in #40213 that (likely) due to a
missing Range deletion tombstone, this invariant can be violated
in practice.

This assertion will allow us to catch this kind of violation without
the need for a MsgVote to race with a MsgSnap, hopefully making the
bug implied by #40213 easier to track down.

Release note: None

40472: opt: detect zero-cardinality semi/anti joins r=rytaft a=rytaft

This commit adds two normalization rules to detect zero-cardinality
semi and anti joins, and replace them with an empty `Values`.

It also updates the stats estimate to ensure that the row count of semi
and anti joins is not zero unless the cardinality is zero.

Fixes #40456
Fixes #40440
Fixes #40394

Release note: None

Co-authored-by: Rohan Yadav <rohany@alumni.cmu.edu>
Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
@craig craig bot closed this as completed in a030638 Sep 5, 2019
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. O-sqlsmith
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants