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: needed column not produced by group-by input #40296

Closed
maddyblue opened this issue Aug 28, 2019 · 0 comments · Fixed by #40523
Closed

sql: internal error: needed column not produced by group-by input #40296

maddyblue opened this issue Aug 28, 2019 · 0 comments · Fixed by #40523
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 AS _int8 FROM generate_series(NULL, NULL) AS g;

WITH
	with_22568
		AS (
			SELECT
				*
			FROM
				(VALUES (0, 0:::OID, NULL, ''))
					AS tab_115060
						(
							col_279740,
							col_279741,
							col_279742,
							col_279743
						)
			UNION
				SELECT
					*
				FROM
					(
						VALUES
							(
								NULL,
								0:::OID,
								'1970-09-08'::DATE
								- ((0) >> 0)
								+ '-40 years -7 mons -488 days -23:07:39.603571',
								NULL
							)
					)
						AS tab_115061
							(
								col_279744,
								col_279745,
								col_279746,
								col_279747
							)
		)
SELECT
	NULL
FROM
	tab_orig AS tab_115062, with_22568
WHERE
	EXISTS(
		WITH
			with_22569 AS (SELECT NULL)
		SELECT
			with_22568.col_279741, tab_115062._int8
	);
pq: internal error: needed column not produced by group-by input
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:1027: buildGroupByInput()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:861: buildGroupBy()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:198: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:493: buildSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:192: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:535: buildProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:195: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:1410: buildWith()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:255: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/builder.go:117: build()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/builder.go:105: Build()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:169: 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()

explain (opt):

  with &1 (with_22568)                                                         
   ├── union                                                                   
   │    ├── values                                                             
   │    │    └── (0, 0, '', NULL)                                              
   │    └── values                                                             
   │         └── (0, '1928-10-07 00:52:20.396429+00:00', NULL, NULL)           
   └── project                                                                 
        ├── select                                                             
        │    ├── group-by                                                      
        │    │    ├── project                                                  
        │    │    │    ├── inner-join-apply                                    
        │    │    │    │    ├── scan tab_115062                                
        │    │    │    │    ├── inner-join-apply                               
        │    │    │    │    │    ├── with-scan &1 (with_22568)                 
        │    │    │    │    │    ├── with &2 (with_22569)                      
        │    │    │    │    │    │    ├── values                               
        │    │    │    │    │    │    │    └── (NULL,)                         
        │    │    │    │    │    │    └── values                               
        │    │    │    │    │    │         └── (col_279741, tab_115062._int8)  
        │    │    │    │    │    └── filters (true)                            
        │    │    │    │    └── filters (true)                                 
        │    │    │    └── projections                                         
        │    │    │         └── true                                           
        │    │    └── aggregations                                             
        │    │         └── const-not-null-agg                                  
        │    │              └── variable: true                                 
        │    └── filters                                                       
        │         └── true_agg IS NOT NULL                                     
        └── projections                                                        
             └── null 

So probably that apply join bug? Maybe not but this was a new error message so I'm filing it.

@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 28, 2019
@RaduBerinde RaduBerinde assigned rytaft and unassigned RaduBerinde Sep 5, 2019
rytaft added a commit to rytaft/cockroach that referenced this issue Sep 5, 2019
This commit fixes the functional dependencies and stats calculation
for WithScanExpr so they use the output columns rather than the input
columns.

Fixes cockroachdb#40296

Release note: None
craig bot pushed a commit that referenced this issue Sep 9, 2019
40523: opt: fix functional deps and stats for WithScanExpr r=rytaft a=rytaft

This commit fixes the functional dependencies and stats calculation
for `WithScanExpr` so they use the output columns rather than the input
columns.

Fixes #40296

Release note: None

40601: sql: fix wrong representation of SHOW JOBS r=spaskob a=spaskob

`WHEN COMPLETE` was wrongly being put in the end of the string
representation of `SHOW JOBS WHEN COMPLETE SELECT...` stmt.

Fixes: #40534.

Release note (bug fix): None

Co-authored-by: Rebecca Taft <[email protected]>
Co-authored-by: Spas Bojanov <[email protected]>
@craig craig bot closed this as completed in e82388f Sep 9, 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.

3 participants