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 #38344

Closed
maddyblue opened this issue Jun 21, 2019 · 0 comments · Fixed by #38624
Closed

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

maddyblue opened this issue Jun 21, 2019 · 0 comments · Fixed by #38624
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 table0 (
    col0 STRING NULL, col1 REGCLASS NULL, col2 NAME, col3 CHAR NULL, col4 INT2 NULL, col5 BIT,
    FAMILY fam0 (col2, col1, col0, col5, col4, col3),
    PRIMARY KEY (col5 ASC),
    UNIQUE (col2),
    INDEX (col4 ASC, col5 DESC),
    UNIQUE (col4 DESC, col5 ASC, col3 ASC, col0, col2),
    UNIQUE (col3 ASC, col0, col4 DESC, col2, col1 DESC, col5)
);

CREATE TABLE table1 (
    col0
        FLOAT4,
    col1
        DATE,
    col2
        INT8 NOT NULL,
    col3
        REGPROCEDURE NULL,
    col4
        REGTYPE NOT NULL,
    col5
        BIT(7) NOT NULL,
    col6
        TIMESTAMP NULL,
    col7
        REGTYPE NULL,
    col8
        FLOAT4 NOT NULL,
    FAMILY fam0 (col4),
    FAMILY fam1 (col1),
    FAMILY fam2 (col2, col5, col0, col6),
    FAMILY fam3 (col7, col8),
    FAMILY fam4 (col3),
    PRIMARY KEY (col4),
    INDEX (col4 DESC, col1 ASC, col5 ASC, col8),
    UNIQUE (col4 ASC, col2 DESC, col5 DESC, col1 DESC, col0 ASC, col3 DESC),
    UNIQUE (col6 ASC, col7 DESC, col3 ASC, col4, col8 ASC, col0 DESC)
);

WITH
    with_451 (col_5560, col_5561)
        AS (
            SELECT
                (
                    (('32.191.188.245/23':::INET::INET + tab_2053.col2::INT8)::INET::INET - tab_2048.col4::INT8)::INET::INET
                    << netmask('81.201.140.125/4':::INET::INET)::INET::INET
                )::BOOL
                    AS col_5560,
                ARRAY[
                    (-3502708866526744067):::INT8,
                    4308645775874943963:::INT8,
                    (-1655863850045721931):::INT8,
                    (-7793802717255130528):::INT8,
                    (-2147483648):::INT8
                ]
                    AS col_5561
            FROM
                defaultdb.public.table1 AS tab_2045,
                defaultdb.public.table1 AS tab_2046
                INNER JOIN defaultdb.public.table1 AS tab_2047 ON
                        not_like_escape(
                            e'o\x14':::STRING::STRING,
                            '':::STRING::STRING,
                            quote_literal((((NOT false) != true) AND true)):::STRING::STRING::STRING
                        )::BOOL
                LEFT JOIN defaultdb.public.table0 AS tab_2048
                    LEFT JOIN defaultdb.public.table1 AS tab_2049 ON true
                    INNER JOIN defaultdb.public.table1 AS tab_2050 ON true OR false IS true
                    CROSS JOIN defaultdb.public.table0 AS tab_2051 ON false,
                defaultdb.public.table0 AS tab_2052,
                defaultdb.public.table1 AS tab_2053
                RIGHT JOIN defaultdb.public.table0 AS tab_2054 ON false,
                defaultdb.public.table1 AS tab_2055,
                defaultdb.public.table0 AS tab_2056
        )
SELECT
    e'\x00':::STRING AS col_5562
FROM
    with_451
WHERE
    with_451.col_5560
GROUP BY
    with_451.col_5561;
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/statistics_builder.go:2191: finalizeFromCardinality()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/statistics_builder.go:653: buildSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/logical_props_builder.go:234: buildSelectProps()
github.com/cockroachdb/cockroach/pkg/sql/opt/memo/expr.og.go:13192: MemoizeSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/norm/factory.og.go:841: ConstructSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:793: buildWhere()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:665: buildSelectClause()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:617: buildSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:220: buildStmt()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:155: Build()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:414: buildExecMemo()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:146: makeOptimizerPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:762: makeExecPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:647: dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:419: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:101: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1206: execCmd()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1142: run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:444: ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:582: func1()
@maddyblue maddyblue added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sqlsmith labels Jun 21, 2019
rytaft added a commit to rytaft/cockroach that referenced this issue Jul 2, 2019
This commit fixes a floating point precision error in the
statisticsBuilder code for estimating the selectivity due to
a null-rejecting filter.

Prior to this commit, the code was subtracting one from the
nullsRemoved estimate if needed to avoid estimating selectivity=0.
But the problem is, if nullsRemoved is extremely large (e.g., 2e+20),
subtracting 1 does nothing since it's below the precision threshold.
This commit changes the logic so now we multiply nullsRemoved by
0.9999999 if necessary. This has the same effect as subtracting 1,
but without the risk of a floating point error.

Fixes cockroachdb#38344

Release note: None
rytaft added a commit to rytaft/cockroach that referenced this issue Jul 2, 2019
This commit fixes a floating point precision error in the
statisticsBuilder code for estimating the selectivity due to
a null-rejecting filter.

Prior to this commit, the code was subtracting one from the
nullsRemoved estimate if needed to avoid estimating selectivity=0.
But the problem is, if nullsRemoved is extremely large (e.g., 2e+20),
subtracting 1 does nothing since it's below the precision threshold.
This commit changes the logic so now we directly multiply the
selectivity by a small number (1e-7) if necessary. This has the same
effect as subtracting 1 from nullsRemoved, but without the risk of
a floating point error.

Fixes cockroachdb#38344

Release note: None
craig bot pushed a commit that referenced this issue Jul 3, 2019
38624: opt: fix floating point precision error in statisticsBuilder r=rytaft a=rytaft

This commit fixes a floating point precision error in the
`statisticsBuilder` code for estimating the selectivity due to
a null-rejecting filter.

Prior to this commit, the code was subtracting one from the
`nullsRemoved` estimate if needed to avoid estimating selectivity=0.
But the problem is, if `nullsRemoved` is extremely large (e.g., 2e+20),
subtracting 1 does nothing since it's below the precision threshold.
This commit changes the logic so now we multiply `nullsRemoved` by
0.9999999 if necessary. This has the same effect as subtracting 1,
but without the risk of a floating point error.

Fixes #38344

Release note: None

Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
@craig craig bot closed this as completed in #38624 Jul 3, 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