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: unsupported comparison #39438

Closed
Tracked by #40649
maddyblue opened this issue Aug 8, 2019 · 6 comments
Closed
Tracked by #40649

sql: panic: unsupported comparison #39438

maddyblue opened this issue Aug 8, 2019 · 6 comments
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
		g % 2 = 0 AS _bool
	FROM
		generate_series(0, 5) AS g;

SELECT
	NULL
FROM
	tab_orig AS tab_181577
WHERE
	EXISTS(
		SELECT
			NULL
		FROM
			tab_orig
			FULL JOIN tab_orig AS tab_181582 ON
					tab_181577._bool
					OR (SELECT 0)
						IN (
								SELECT
									0
								FROM
									tab_orig AS tab_181583
								WHERE
									EXISTS(
										SELECT
											NULL
										FROM
											tab_orig
												AS tab_181585
											LEFT JOIN tab_orig ON
													NOT
														tab_181583._bool
										HAVING
											bool_or(
												tab_181585._bool
											)
									)
							)
			CROSS JOIN tab_orig AS tab_181594
	);
	panic: panic while executing 1 statements: SELECT _ FROM _ AS _ WHERE EXISTS (SELECT _ FROM _ FULL JOIN _ AS _ ON _._ OR ((SELECT _) IN (SELECT _ FROM _ AS _ WHERE EXISTS (SELECT _ FROM _ AS _ LEFT JOIN _ ON NOT _._ HAVING bool_or(_._)))) CROSS JOIN _ AS _); caused by unsupported comparison: tuple{int} to int

goroutine 602 [running]:
github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).closeWrapper(0xc0015d8d80, 0x4554920, 0xc0014fa680, 0x39d6ca0, 0xc000475550)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:727 +0x330
github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn.func1(0xc0015d8d80, 0x4554920, 0xc0014fa680)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:440 +0x61
panic(0x39d6ca0, 0xc000475550)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.(*DTuple).Compare(0xc00117ff20, 0xc001783d40, 0x45b4d80, 0xc00086abf8, 0x3b9f200)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/datum.go:2704 +0x217
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.cmpOpScalarFn(0xc001783d40, 0x45b5320, 0xc00117ff20, 0x45b4d80, 0xc00086abf8, 0x0, 0x0, 0x45b4d80)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/eval.go:2136 +0x14b
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.cmpOpScalarEQFn(0xc001783d40, 0x45b5320, 0xc00117ff20, 0x45b4d80, 0xc00086abf8, 0x0, 0x45602a0, 0xc00117ff20, 0x4560060)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/eval.go:2141 +0x5c
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.(*ComparisonExpr).Eval(0xc00110c780, 0xc001783d40, 0xc00110c780, 0x4581e80, 0xc00110c780, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/eval.go:3697 +0x55d
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.(*AndExpr).Eval(0xc00120ae40, 0xc001783d40, 0x2800, 0x100000, 0xc000cd58c0, 0xc000825b20)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/eval.go:2828 +0x65
github.com/cockroachdb/cockroach/pkg/sql/sqlbase.RunFilter(0x4581ac0, 0xc00120ae40, 0xc001783d40, 0x0, 0x0, 0xc00025b501)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/sqlbase/expr_filter.go:21 +0x48
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*exprHelper).evalFilter(0xc001597680, 0xc00105fb00, 0x2, 0x2, 0x0, 0x0, 0x25f033a)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/expr.go:176 +0xf3
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*ProcOutputHelper).ProcessRow(0xc000a13118, 0x45549e0, 0xc00120b740, 0xc00105fb00, 0x2, 0x2, 0xc00160a400, 0xc00160a470, 0x0, 0x0, ...)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:346 +0x48d
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*ProcessorBase).ProcessRowHelper(0xc000a13100, 0xc00105fb00, 0x2, 0x2, 0x0, 0x3a8c0c0, 0x3b45f20)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:770 +0x78
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*tableReader).Next(0xc000a13100, 0x20, 0x39e55e0, 0x65d5de0, 0xc00123db00)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/tablereader.go:281 +0x7e
github.com/cockroachdb/cockroach/pkg/sql.(*rowSourceToPlanNode).Next(0xc0015978c0, 0x45549e0, 0xc00120b740, 0xc001596fc0, 0xc0015d90d0, 0x39e53a0, 0x3983d20, 0xc0016eb600)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/row_source_to_plan_node.go:75 +0x48
github.com/cockroachdb/cockroach/pkg/sql.(*applyJoinNode).Next(0xc0016eb600, 0x45549e0, 0xc00120b740, 0xc001596fc0, 0xc0015d90d0, 0x0, 0x45549e0, 0xc00120b740)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:216 +0x2d8
github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Next(0xc001604500, 0xc0015d90d0, 0x4555a60, 0xc0016eb600, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:171 +0x43c
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.Run(0x45549e0, 0xc00120b740, 0x4567120, 0xc001604500, 0x4531ea0, 0xc00142b880)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/base.go:171 +0x35
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*ProcessorBase).Run(0xc001604500, 0x45549e0, 0xc00120b740)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:793 +0x92
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*Flow).Run(0xc0014178c0, 0x45549e0, 0xc00120b740, 0x3e226b0, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:581 +0x1ef
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).Run(0xc0005d7440, 0xc00105f9e0, 0xc0012702d0, 0xc000a27c88, 0xc0011e9340, 0xc001596d80, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:333 +0x381
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).planAndRunSubquery(0xc0005d7440, 0x45549e0, 0xc00119c330, 0x2, 0xc00120aea0, 0x1, 0x1, 0x4556460, 0xc00152cd70, 0x0, ...)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:860 +0x7c8
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).PlanAndRunSubqueries(0xc0005d7440, 0x45549e0, 0xc00119c330, 0xc0015d90d0, 0xc000a27f48, 0xc0008d1c30, 0x3, 0x3, 0xc0011e8b00, 0xc0015d8f01, ...)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:764 +0x1ba
github.com/cockroachdb/cockroach/pkg/sql.(*applyJoinNode).runRightSidePlan(0xc000ce5e00, 0x45549e0, 0xc00119c330, 0xc0013ec6c0, 0xc0015d90d0, 0xc0014c2600, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:303 +0x26b
github.com/cockroachdb/cockroach/pkg/sql.(*applyJoinNode).Next(0xc000ce5e00, 0x45549e0, 0xc00119c330, 0xc0013ec6c0, 0xc0015d90d0, 0x1, 0x1, 0x45b4920)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:273 +0x6df
github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Next(0xc000fcef00, 0xc000fcef48, 0x1, 0x1, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:171 +0x43c
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.Run(0x45549e0, 0xc00119c330, 0x4567120, 0xc000fcef00, 0x4531ea0, 0xc0013da000)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/base.go:171 +0x35
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*ProcessorBase).Run(0xc000fcef00, 0x45549e0, 0xc00119c330)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:793 +0x92
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun.(*Flow).Run(0xc0013dcfc0, 0x45549e0, 0xc00119c330, 0x3e226b0, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:581 +0x1ef
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).Run(0xc0005d7440, 0xc00169b440, 0xc0012702d0, 0xc000a28870, 0xc000f13340, 0xc0015d91a8, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:333 +0x381
github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLPlanner).PlanAndRun(0xc0005d7440, 0x45549e0, 0xc001493920, 0xc0015d91a8, 0xc00169b440, 0xc0012702d0, 0x45567a0, 0xc001544fc0, 0xc000f13340, 0xc0015d8f00)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:942 +0x20a
github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execWithDistSQLEngine(0xc0015d8d80, 0x45549e0, 0xc001493920, 0xc0015d90d0, 0x3, 0x7f2e4f5b88d0, 0xc0011d0668, 0xc000a28a00, 0x0, 0x0, ...)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:910 +0x370
github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).dispatchToExecutionEngine(0xc0015d8d80, 0x45549e0, 0xc001493920, 0xc0015d90d0, 0x7f2e4f5b88d0, 0xc0011d0668, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:734 +0x6e5
github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execStmtInOpenState(0xc0015d8d80, 0x45549e0, 0xc001493920, 0x4560ee0, 0xc000f5fdc0, 0xc0008ddb08, 0x257, 0x0, 0x7, 0x0, ...)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:417 +0xb64
github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execStmt(0xc0015d8d80, 0x45549e0, 0xc001493920, 0x4560ee0, 0xc000f5fdc0, 0xc0008ddb08, 0x257, 0x0, 0x7, 0x0, ...)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:99 +0x4ec
github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execCmd(0xc0015d8d80, 0x4554920, 0xc000f5fe00, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1211 +0x1aba
github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).run(0xc0015d8d80, 0x4554920, 0xc0014fa680, 0xc0003e1300, 0x5400, 0x15000, 0xc0003e1398, 0xc0004381e0, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1140 +0x1a3
github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn(0xc00010cd80, 0x4554920, 0xc0014fa680, 0xc0015d8d80, 0x5400, 0x15000, 0xc0003e1398, 0xc0004381e0, 0x0, 0x0)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:442 +0xce
github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*conn).processCommandsAsync.func1(0xc0003ac4e9, 0xc0002ff8a0, 0x4554920, 0xc0014fa680, 0xc0004381e0, 0xc00010cd80, 0xc0011d0000, 0x455f460, 0xc0002ff880, 0xc001057e00, ...)
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:584 +0x21c
created by github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*conn).processCommandsAsync
	/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:513 +0x17b
@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 8, 2019
@jordanlewis
Copy link
Member

All of these recent panics are to do with apply join. Hopefully they all have the same root case, but I don't know. See #38867 for another issue with apply join.

@yuzefovich
Copy link
Member

#38867 has been fixed, but this issue is still present. I agree with Jordan that it appears the problem is with apply join (more specifically, with nested apply joins).

If we remove one "query layer" (the outer main query), it successfully executes:

root@127.0.0.1:49280/movr> SELECT
                        NULL
                FROM
                        tab_orig
                        FULL JOIN tab_orig AS tab_181582 ON
                                        tab_orig._bool
                                        OR (SELECT (0))
                                                IN (
                                                                SELECT
                                                                        0
                                                                FROM
                                                                        tab_orig AS tab_181583
                                                                WHERE
                                                                        EXISTS(
                                                                                SELECT
                                                                                        NULL
                                                                                FROM
                                                                                        tab_orig
                                                                                                AS tab_181585
                                                                                        LEFT JOIN tab_orig ON
                                                                                                        NOT
                                                                                                                tab_181583._bool
                                                                                HAVING
                                                                                        bool_or(
                                                                                                tab_181585._bool
                                                                                        )
                                                                        )
                                                        )
                        CROSS JOIN tab_orig AS tab_181594;
  ?column?  
+----------+
  NULL      
...

Apply join is still present, but it is single (unlike in the query that panics when we have a couple of nested apply joins):

  project                                                                            
   ├── inner-join (hash)                                                             
   │    ├── full-join (hash)                                                         
   │    │    ├── scan tab_orig                                                       
   │    │    ├── scan tab_181582                                                     
   │    │    └── filters                                                             
   │    │         └── or                                                             
   │    │              ├── variable: tab_orig._bool                                  
   │    │              └── any: eq                                                   
   │    │                   ├── project                                              
   │    │                   │    ├── semi-join-apply                                 
   │    │                   │    │    ├── scan tab_181583                            
   │    │                   │    │    ├── scalar-group-by                            
   │    │                   │    │    │    ├── left-join (hash)                      
   │    │                   │    │    │    │    ├── scan tab_181585                  
   │    │                   │    │    │    │    ├── scan tab_orig                    
   │    │                   │    │    │    │    └── filters                          
   │    │                   │    │    │    │         └── NOT tab_181583._bool        
   │    │                   │    │    │    └── aggregations                          
   │    │                   │    │    │         └── bool-or                          
   │    │                   │    │    │              └── variable: tab_181585._bool  
   │    │                   │    │    └── filters                                    
   │    │                   │    │         └── variable: bool_or                     
   │    │                   │    └── projections                                     
   │    │                   │         └── const: 0                                   
   │    │                   └── subquery                                             
   │    │                        └── values                                          
   │    │                             └── (0,)                                       
   │    ├── scan tab_181594                                                          
   │    └── filters (true)                                                           
   └── projections                                                                   
        └── null  

I'm not sure where to go from here. Maybe @rytaft has pointers since you've recently fixed another issue with apply joins?

@jordanlewis
Copy link
Member

I "instrumented" the apply join here (read: added a println of all re-planned right sides) and found the following plan that gets produced and attempted to execute right before the crash:

inner-join (hash)
 ├── columns:
 ├── stats: [rows=333333333]
 ├── cost: 3367063.6
 ├── full-join (hash)
 │    ├── columns:
 │    ├── stats: [rows=333333.333]
 │    ├── cost: 28526.0708
 │    ├── scan tab_orig
 │    │    ├── columns:
 │    │    ├── stats: [rows=1000]
 │    │    └── cost: 1020.02
 │    ├── scan tab_181582
 │    │    ├── columns:
 │    │    ├── stats: [rows=1000]
 │    │    └── cost: 1020.02
 │    └── filters
 │         └── exists [type=bool, subquery]
 │              └── limit
 │                   ├── columns: tab_181583._bool:8(bool)
 │                   ├── cardinality: [0 - 1]
 │                   ├── stats: [rows=1]
 │                   ├── cost: 23122.6875
 │                   ├── key: ()
 │                   ├── fd: ()-->(8)
 │                   ├── semi-join-apply
 │                   │    ├── columns: tab_181583._bool:8(bool)
 │                   │    ├── stats: [rows=111.111111]
 │                   │    ├── cost: 23122.6675
 │                   │    ├── select
 │                   │    │    ├── columns: tab_181583._bool:8(bool)
 │                   │    │    ├── stats: [rows=111.111111]
 │                   │    │    ├── cost: 1040.07
 │                   │    │    ├── prune: (8)
 │                   │    │    ├── scan tab_181583
 │                   │    │    │    ├── columns: tab_181583._bool:8(bool)
 │                   │    │    │    ├── stats: [rows=1000]
 │                   │    │    │    ├── cost: 1030.02
 │                   │    │    │    └── prune: (8)
 │                   │    │    └── filters
 │                   │    │         ├── eq [type=bool, subquery]
 │                   │    │         │    ├── subquery [type=int]
 │                   │    │         │    │    └── values
 │                   │    │         │    │         ├── columns: "?column?":7(int!null)
 │                   │    │         │    │         ├── cardinality: [1 - 1]
 │                   │    │         │    │         ├── stats: [rows=1]
 │                   │    │         │    │         ├── cost: 0.02
 │                   │    │         │    │         ├── key: ()
 │                   │    │         │    │         ├── fd: ()-->(7)
 │                   │    │         │    │         └── tuple [type=tuple{int}]
 │                   │    │         │    │              └── const: 0 [type=int]
 │                   │    │         │    └── const: 0 [type=int]
 │                   │    │         └── eq [type=bool, subquery]
 │                   │    │              ├── subquery [type=int]
 │                   │    │              │    └── values
 │                   │    │              │         ├── columns: "?column?":7(int!null)
 │                   │    │              │         ├── cardinality: [1 - 1]
 │                   │    │              │         ├── stats: [rows=1]
 │                   │    │              │         ├── cost: 0.02
 │                   │    │              │         ├── key: ()
 │                   │    │              │         ├── fd: ()-->(7)
 │                   │    │              │         └── tuple [type=tuple{int}]
 │                   │    │              │              └── const: 0 [type=int]
 │                   │    │              └── const: 0 [type=int]
 │                   │    ├── scalar-group-by
 │                   │    │    ├── columns: bool_or:14(bool)
 │                   │    │    ├── outer: (8)
 │                   │    │    ├── cardinality: [1 - 1]
 │                   │    │    ├── stats: [rows=1]
 │                   │    │    ├── cost: 22080.07
 │                   │    │    ├── key: ()
 │                   │    │    ├── fd: ()-->(14)
 │                   │    │    ├── prune: (14)
 │                   │    │    ├── left-join (hash)
 │                   │    │    │    ├── columns: tab_181585._bool:10(bool)
 │                   │    │    │    ├── outer: (8)
 │                   │    │    │    ├── stats: [rows=1000000, distinct(8)=1, null(8)=0]
 │                   │    │    │    ├── cost: 12080.05
 │                   │    │    │    ├── scan tab_181585
 │                   │    │    │    │    ├── columns: tab_181585._bool:10(bool)
 │                   │    │    │    │    ├── stats: [rows=1000]
 │                   │    │    │    │    └── cost: 1030.02
 │                   │    │    │    ├── scan tab_orig
 │                   │    │    │    │    ├── stats: [rows=1000]
 │                   │    │    │    │    └── cost: 1020.02
 │                   │    │    │    └── filters
 │                   │    │    │         └── not [type=bool, outer=(8), constraints=(/8: [/false - /false]; tight), fd=()-->(8)]
 │                   │    │    │              └── variable: tab_181583._bool [type=bool]
 │                   │    │    └── aggregations
 │                   │    │         └── bool-or [type=bool, outer=(10)]
 │                   │    │              └── variable: tab_181585._bool [type=bool]
 │                   │    └── filters
 │                   │         └── variable: bool_or [type=bool, outer=(14), constraints=(/14: [/true - /true]; tight), fd=()-->(14)]
 │                   └── const: 1 [type=int]
 ├── scan tab_181594
 │    ├── columns:
 │    ├── stats: [rows=1000]
 │    └── cost: 1020.02
 └── filters (true)

This plan seems like it might be the problem (or I'm misreading it). I'll paste just the suspicious part:

 │                   │    │         ├── eq [type=bool, subquery]
 │                   │    │         │    ├── subquery [type=int]
 │                   │    │         │    │    └── values
 │                   │    │         │    │         ├── columns: "?column?":7(int!null)
 │                   │    │         │    │         ├── cardinality: [1 - 1]
 │                   │    │         │    │         ├── stats: [rows=1]
 │                   │    │         │    │         ├── cost: 0.02
 │                   │    │         │    │         ├── key: ()
 │                   │    │         │    │         ├── fd: ()-->(7)
 │                   │    │         │    │         └── tuple [type=tuple{int}]
 │                   │    │         │    │              └── const: 0 [type=int]
 │                   │    │         │    └── const: 0 [type=int]

This seems to be an equality projection between constant 0 and a subquery that returns a tuple{int}? But the subquery also says it returns int, so maybe I'm just misreading it.

@rytaft could you please glance at this last plan - does this look off?

@rytaft
Copy link
Collaborator

rytaft commented Aug 20, 2019

It does look a bit weird, but it's the same as the explain output for the following simple query:

root@127.0.0.1:58889/defaultdb> explain (opt,types) select * from (select 1) where (select 0) = 0 and (select 0) = 0;
                                 text                                 
+--------------------------------------------------------------------+
  select                                                              
   ├── columns: "?column?":1(int!null)                                
   ├── cardinality: [0 - 1]                                           
   ├── stats: [rows=0.111111111, distinct(1)=0.111111111, null(1)=0]  
   ├── cost: 0.08                                                     
   ├── key: ()                                                        
   ├── fd: ()-->(1)                                                   
   ├── prune: (1)                                                     
   ├── values                                                         
   │    ├── columns: "?column?":1(int!null)                           
   │    ├── cardinality: [1 - 1]                                      
   │    ├── stats: [rows=1, distinct(1)=1, null(1)=0]                 
   │    ├── cost: 0.02                                                
   │    ├── key: ()                                                   
   │    ├── fd: ()-->(1)                                              
   │    ├── prune: (1)                                                
   │    └── tuple [type=tuple{int}]                                   
   │         └── const: 1 [type=int]                                  
   └── filters                                                        
        ├── eq [type=bool, subquery]                                  
        │    ├── subquery [type=int]                                  
        │    │    └── values                                          
        │    │         ├── columns: "?column?":2(int!null)            
        │    │         ├── cardinality: [1 - 1]                       
        │    │         ├── stats: [rows=1]                            
        │    │         ├── cost: 0.02                                 
        │    │         ├── key: ()                                    
        │    │         ├── fd: ()-->(2)                               
        │    │         └── tuple [type=tuple{int}]                    
        │    │              └── const: 0 [type=int]                   
        │    └── const: 0 [type=int]                                  
        └── eq [type=bool, subquery]                                  
             ├── subquery [type=int]                                  
             │    └── values                                          
             │         ├── columns: "?column?":3(int!null)            
             │         ├── cardinality: [1 - 1]                       
             │         ├── stats: [rows=1]                            
             │         ├── cost: 0.02                                 
             │         ├── key: ()                                    
             │         ├── fd: ()-->(3)                               
             │         └── tuple [type=tuple{int}]                    
             │              └── const: 0 [type=int]                   
             └── const: 0 [type=int]                                  
(43 rows)

And I checked that running it gives no error:

root@127.0.0.1:58889/defaultdb> select * from (select 1) where (select 0) = 0 and (select 0) = 0;
  ?column?  
+----------+
         1  
(1 row)

I'll dig into this a bit more to see if I can find anything...

@rytaft
Copy link
Collaborator

rytaft commented Aug 20, 2019

Just to close the loop here (already discussed offline): it seems that the problem is related to the fact that since the right side plan for applyJoin is always local, the subqueries are not evaluated and replaced as they would be otherwise.

If you look at distsqlplan.MakeExpression, you can see that evalAndReplaceSubqueryVisitor is not used when the the context is local.

@yuzefovich
Copy link
Member

This query now hits the same issue with apply join as #39433, so closing as duplicate.

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

No branches or pull requests

5 participants