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: panic: invalid datum type given: tuple{string}, expected unknown #40394

Closed
maddyblue opened this issue Aug 31, 2019 · 3 comments · Fixed by #40472
Closed

sql: panic: invalid datum type given: tuple{string}, expected unknown #40394

maddyblue opened this issue Aug 31, 2019 · 3 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

maddyblue commented Aug 31, 2019

CREATE TABLE IF NOT EXISTS tab_orig AS
	SELECT
		'0.0.0.0'::INET + g AS _inet
	FROM
		generate_series(0, 0) AS g;

  WITH with_604 AS (
                    SELECT *
                      FROM (VALUES ('')) AS tab_2870 (
                                                        col_7201
                                                     )
                )
SELECT NULL
  FROM tab_orig AS tab_2874
 WHERE NULL::INET
       NOT IN (
              WITH with_606 AS (
                                SELECT *
                                  FROM (
                                        VALUES (
                                                (
                                                    SELECT
                                                        NULL
                                                )
                                               )
                                       ) AS tab_2878 (
                                                        col_7216
                                                     )
                            )
            SELECT tab_2874._inet
        );
github.com/cockroachdb/cockroach/pkg/sql/sqlbase.DatumToEncDatum(0xc0015dfc00, 0x4d87740, 0xc00140c3c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlbase/encoded_datum.go:167 +0x1e2
github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Next(0xc001801900, 0xc001961050, 0x3, 0x3, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:179 +0x517
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.Run(0x4d020a0, 0xc0016e3180, 0x4d2c5e0, 0xc001801900, 0x4cdc1e0, 0xc0019fe700)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/base.go:171 +0x35
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*ProcessorBase).Run(0xc001801900, 0x4d020a0, 0xc0016e3180)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:793 +0x92
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*Flow).startInternal.func1(0xc00111c000, 0xc0004cff50, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:523 +0x65
created by github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*Flow).startInternal
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:522 +0x35b
@maddyblue maddyblue added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sqlsmith labels Aug 31, 2019
@jordanlewis jordanlewis assigned rohany and unassigned jordanlewis and solongordon Sep 3, 2019
@yuzefovich
Copy link
Member

Huh, at the moment, on master it fails with

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()

The PR that causes the query to fail prior to hitting the panic is #40248. cc @rytaft

@yuzefovich yuzefovich assigned yuzefovich and unassigned rohany Sep 4, 2019
@yuzefovich
Copy link
Member

This appears to be yet another apply join related panic:

panic: invalid datum type given: tuple{string}, expected unknown [recovered]
	panic: panic while executing 1 statements: WITH _ AS (SELECT * FROM (VALUES (_)) AS _ (_)) SELECT _ FROM _ AS _ WHERE _::INET NOT IN (WITH _ AS (SELECT * FROM (VALUES ((SELECT _))) AS _ (_)) SELECT _._); caused by invalid datum type given: tuple{string}, expected unknown

goroutine 1111 [running]:
github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).closeWrapper(0xc00183f000, 0x856afc0, 0xc001068980, 0x75a0b20, 0xc0011274d0)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:730 +0x330
github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn.func1(0xc00183f000, 0x856afc0, 0xc001068980)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:442 +0x61
panic(0x75a0b20, 0xc0011274d0)
	/usr/local/opt/go/libexec/src/runtime/panic.go:522 +0x1b5
github.com/cockroachdb/cockroach/pkg/sql/sqlbase.DatumToEncDatum(0xc00131fd00, 0x85f1240, 0xc0007226f0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlbase/encoded_datum.go:167 +0x1e2
github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Next(0xc001614a00, 0xc00183f358, 0x856c100, 0xc0013de300, 0x0)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:179 +0x517
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.Run(0x856afc0, 0xc001972ac0, 0x8596000, 0xc001614a00, 0x8545100, 0xc0006cb880)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/base.go:171 +0x35
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*ProcessorBase).Run(0xc001614a00, 0x856afc0, 0xc001972ac0)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:793 +0x92
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*Flow).Run(0xc001993320, 0x856b080, 0xc0013de570, 0x7d4c0b8, 0x0, 0x0)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:584 +0x1ec
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).Run(0xc000130780, 0xc0018a1f20, 0xc00140f290, 0xc00234bb58, 0xc001373b80, 0xc001642480, 0x0, 0x0)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:337 +0x381
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).planAndRunSubquery(0xc000130780, 0x856afc0, 0xc0019725c0, 0x1, 0xc0013de330, 0x3, 0x1, 0x856c100, 0xc0013de300, 0x0, ...)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:880 +0x7c8
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).PlanAndRunSubqueries(0xc000130780, 0x856afc0, 0xc0019725c0, 0xc00183f358, 0xc00234be18, 0xc0004e1180, 0x2, 0x2, 0xc001373600, 0xc00183f101, ...)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:784 +0x1ba
github.com/cockroachdb/cockroach/pkg/sql.(*applyJoinNode).runRightSidePlan(0xc0014e0600, 0x856afc0, 0xc0019725c0, 0xc0015c2d80, 0xc00183f358, 0xc0013da0c0, 0x0, 0x0)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:310 +0x26b
github.com/cockroachdb/cockroach/pkg/sql.(*applyJoinNode).Next(0xc0014e0600, 0x856afc0, 0xc0019725c0, 0xc0015c2d80, 0xc00183f358, 0x0, 0x856afc0, 0xc0019725c0)
	/Users/yahoryuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:280 +0x6df
github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Next(0xc001614000, 0xc00183f358, 0x856c0c0, 0xc0014e0600, 0x0)
...

I reduced the reproduction (updated the first comment above).
cc @solongordon

@rytaft
Copy link
Collaborator

rytaft commented Sep 5, 2019

Similar to #40440, this will be fixed when #40472 merges. The plan is reduced to:

  values                                    
   ├── columns: "?column?":7(unknown!null)  
   ├── cardinality: [0 - 0]                 
   ├── stats: [rows=0]                      
   ├── cost: 0.01                           
   ├── key: ()                              
   ├── fd: ()-->(7)                         
   └── prune: (7)                           

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.

6 participants