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

When DEBUG4 is enabled, Citus regression tests crashes in several places #4860

Closed
onderkalaci opened this issue Mar 29, 2021 · 19 comments
Closed
Assignees
Labels
Milestone

Comments

@onderkalaci
Copy link
Member

4b44e3d

Simply add the following to src/test/regress/pg_regress_multi.pl

push(@pgOptions, "log_min_messages=debug4");
@metdos metdos added this to the 10.0 Release milestone Mar 30, 2021
@metdos
Copy link
Contributor

metdos commented Mar 30, 2021

Adding cherry-pick label to keep track.

@agedemenli agedemenli self-assigned this May 7, 2021
@agedemenli
Copy link
Contributor

@onderkalaci
Copy link
Member Author

Can you share an example query which triggers the crash?

@agedemenli
Copy link
Contributor

create table users_table (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint);
select create_distributed_table('users_table', 'user_id');

create table events_table (user_id int, time timestamp, event_type int, value_2 int, value_3 float, value_4 bigint);
select create_distributed_table('events_table', 'user_id');


insert into users_table select i % 10000, timestamp '2014-01-10 20:00:00' +
       i * (timestamp '2014-01-20 20:00:00' -
                   timestamp '2014-01-10 10:00:00'),i, i % 100, i % 5 from generate_series(0, 1000) i;


insert into events_table select i % 10000, timestamp '2014-01-10 20:00:00' +
       i * (timestamp '2014-01-20 20:00:00' -
                   timestamp '2014-01-10 10:00:00'),i, i % 100, i % 5 from generate_series(0, 10000) i;

set log_min_messages=debug4;

SELECT
	us.user_id,
	SUM(us.value_1) OVER (PARTITION BY us.user_id)
FROM
	users_table us
	JOIN
	events_table ev
	ON (us.user_id = ev.user_id)
GROUP BY
	1,
	value_1
ORDER BY
	1,
	2
LIMIT 5;

@agedemenli
Copy link
Contributor

Query object:

{QUERY
   :commandType 1
   :querySource 0
   :canSetTag true
   :utilityStmt <>
   :resultRelation 0
   :hasAggs false
   :hasWindowFuncs false
   :hasTargetSRFs false
   :hasSubLinks false
   :hasDistinctOn false
   :hasRecursive false
   :hasModifyingCTE false
   :hasForUpdate false
   :hasRowSecurity false
   :cteList <>
   :rtable (
      {RTE
      :alias <>
      :eref
         {ALIAS
         :aliasname remote_scan
         :colnames ("user_id" "sum" "worker_column_3")
         }
      :rtekind 3
      :functions (
         {RANGETBLFUNCTION
         :funcexpr
            {FUNCEXPR
            :funcid 16789
            :funcresulttype 2249
            :funcretset true
            :funcvariadic false
            :funcformat 0
            :funccollid 0
            :inputcollid 0
            :args (
               {CONST
               :consttype 23
               :consttypmod 0
               :constcollid 0
               :constlen 4
               :constbyval true
               :constisnull false
               :location -1
               :constvalue 4 [ 10 0 0 0 0 0 0 0 ]
               }
               {CONST
               :consttype 2275
               :consttypmod 0
               :constcollid 0
               :constlen -2
               :constbyval false
               :constisnull true
               :location -1
               :constvalue <>
               }
               {CONST
               :consttype 2275
               :consttypmod 0
               :constcollid 0
               :constlen -2
               :constbyval false
               :constisnull true
               :location -1
               :constvalue <>
               }
               {CONST
               :consttype 2275
               :consttypmod 0
               :constcollid 0
               :constlen -2
               :constbyval false
               :constisnull true
               :location -1
               :constvalue <>
               }
            )
            :location -1
            }
         :funccolcount 4
         :funccolnames ("user_id" "sum" "worker_column_3" "sum")
         :funccoltypes (o 23 20 23 20)
         :funccoltypmods (i -1 -1 -1 -1)
         :funccolcollations (o 0 0 0 0)
         :funcparams (b)
         }
      )
      :funcordinality false
      :lateral false
      :inh false
      :inFromCl true
      :requiredPerms 0
      :checkAsUser 0
      :selectedCols (b)
      :insertedCols (b)
      :updatedCols (b)
      :extraUpdatedCols (b)
      :securityQuals <>
      }
   )
   :jointree
      {FROMEXPR
      :fromlist (
         {RANGETBLREF
         :rtindex 1
         }
      )
      :quals <>
      }
   :targetList (
      {TARGETENTRY
      :expr
         {VAR
         :varno 1
         :varattno 1
         :vartype 23
         :vartypmod -1
         :varcollid 0
         :varlevelsup 0
         :varnoold 1
         :varoattno 1
         :location -1
         }
      :resno 1
      :resname user_id
      :ressortgroupref 1
      :resorigtbl 41827
      :resorigcol 1
      :resjunk false
      }
      {TARGETENTRY
      :expr
         {VAR
         :varno 1
         :varattno 2
         :vartype 20
         :vartypmod -1
         :varcollid 0
         :varlevelsup 0
         :varnoold 1
         :varoattno 2
         :location -1
         }
      :resno 2
      :resname sum
      :ressortgroupref 2
      :resorigtbl 0
      :resorigcol 0
      :resjunk false
      }
      {TARGETENTRY
      :expr
         {VAR
         :varno 1
         :varattno 3
         :vartype 23
         :vartypmod -1
         :varcollid 0
         :varlevelsup 0
         :varnoold 1
         :varoattno 3
         :location -1
         }
      :resno 3
      :resname <>
      :ressortgroupref 3
      :resorigtbl 0
      :resorigcol 0
      :resjunk true
      }
   )
   :override 0
   :onConflict <>
   :returningList <>
   :groupClause <>
   :groupingSets <>
   :havingQual <>
   :windowClause <>
   :distinctClause <>
   :sortClause (
      {SORTGROUPCLAUSE
      :tleSortGroupRef 1
      :eqop 96
      :sortop 97
      :nulls_first false
      :hashable true
      }
      {SORTGROUPCLAUSE
      :tleSortGroupRef 2
      :eqop 410
      :sortop 412
      :nulls_first false
      :hashable true
      }
   )
   :limitOffset <>
   :limitCount
      {CONST
      :consttype 20
      :consttypmod -1
      :constcollid 0
      :constlen 8
      :constbyval true
      :constisnull false
      :location -1
      :constvalue 8 [ 5 0 0 0 0 0 0 0 ]
      }
   :rowMarks <>
   :setOperations <>
   :constraintDeps <>
   :withCheckOptions <>
   :stmt_location 0
   :stmt_len 0
   }

@agedemenli
Copy link
Contributor

As seen in the previous comment, for the given query, colnames are ("user_id" "sum" "worker_column_3").
However, here we try to access colnames[3]. That causes a segmentation fault. We probably expect it to be "sum". I guess so, because at funccolnames, the elements are: ("user_id" "sum" "worker_column_3" "sum")

@agedemenli
Copy link
Contributor

Still, no idea why it only happens when DEBUG4 is enabled

@agedemenli
Copy link
Contributor

agedemenli commented May 10, 2021

In combine_query_planner.c, in BuildSelectStatementViaStdPlanner, we try to print the query if DEBUG4 is enabled.

	/*
	 * Print the combine query at debug level 4. Since serializing the query is relatively
	 * cpu intensive we only perform that if we are actually logging DEBUG4.
	 */
	const int logCombineQueryLevel = DEBUG4;
	if (IsLoggableLevel(logCombineQueryLevel))
	{
		pprint(combineQuery);
		StringInfo queryString = makeStringInfo();
		pg_get_query_def(combineQuery, queryString);
		elog(logCombineQueryLevel, "combine query: %s", queryString->data);
	}

@metdos metdos modified the milestones: 10.0 Release, 10.1 Release May 27, 2021
@agedemenli
Copy link
Contributor

819b5dc

This is what we tried on this. We basically moved the logic that extracts the column names, to RemoteScanTargetList. Because we used to skip the target entries that are marked as resjunk. That prevented this query from crashing.

However, now we are still getting crashes on later queries. And the first crash that happens, happens on Postgres' printing logic. This also makes more difficult to debug.

@metdos
Copy link
Contributor

metdos commented May 28, 2021

However, now we are still getting crashes on later queries. And the first crash that happens, happens on Postgres' printing logic. This also makes more difficult to debug.

Can you find a really old version of citus where we can't replicate this crash, then using binary search for commits you can find the breaking commit?

@agedemenli
Copy link
Contributor

agedemenli commented May 28, 2021

The breaking commit: a77ed9c

It's a huge commit. But the relevant part is here, we added this code piece, which I mentioned before. But I think the cause of the problem is not that. It's just where it's revealed.

@marcocitus
Copy link
Member

marcocitus commented May 31, 2021

Just a note: the example above does not seem to crash in PG13, only on PG12. It may be worth comparing the Query's produced by PG12 and PG13.

@marcocitus
Copy link
Member

PG 13.1, Citus master, no extra "sum":

{QUERY                                                                                                                                                                                                                                                                                                                             
   :commandType 1                                                                                                                                                                                                                                                                                                                              
   :querySource 0                                                                                                                                                                                                                                                                                                                              
   :canSetTag true                                                                                                                                                                                                                                                                                                                             
   :utilityStmt <>                                                                                                                                                                                                                                                                                                                             
   :resultRelation 0                                                                                                                                                                                                                                                                                                                           
   :hasAggs false                                                                                                                                                                                                                                                                                                                              
   :hasWindowFuncs false                                                                                                                                                                                                                                                                                                                       
   :hasTargetSRFs false                                                                                                                                                                                                                                                                                                                        
   :hasSubLinks false                                                                                                                                                                                                                                                                                                                          
   :hasDistinctOn false                                                                                                                                                                                                                                                                                                                        
   :hasRecursive false                                                                                                                                                                                                                                                                                                                         
   :hasModifyingCTE false                                                                                                                                                                                                                                                                                                                      
   :hasForUpdate false                                                                                                                                                                                                                                                                                                                         
   :hasRowSecurity false                                                                                                                                                                                                                                                                                                                       
   :cteList <>                                                                                                                                                                                                                                                                                                                                 
   :rtable (                                                                                                                                                                                                                                                                                                                                   
      {RTE                                                                                                                                                                                                                                                                                                                                     
      :alias <>                                                                                                                                                                                                                                                                                                                                
      :eref                                                                                                                                                                                                                                                                                                                                    
         {ALIAS                                                                                                                                                                                                                                                                                                                                
         :aliasname remote_scan                                                                                                                                                                                                                                                                                                                
         :colnames ("user_id" "sum" "worker_column_3")                                                                                                                                                                                                                                                                                         
         }                                                                                                                                                                                                                                                                                                                                     
      :rtekind 3                                                                                                                                                                                                                                                                                                                               
      :functions (                                                                                                                                                                                                                                                                                                                             
         {RANGETBLFUNCTION                                                                                                                                                                                                                                                                                                                     
         :funcexpr                                                                                                                                                                                                                                                                                                                             
            {FUNCEXPR                                                                                                                                                                                                                                                                                                                          
            :funcid 756329                                                                                                                                                                                                                                                                                                                     
            :funcresulttype 2249                                                                                                                                                                                                                                                                                                               
            :funcretset true                                                                                                                                                                                                                                                                                                                   
            :funcvariadic false                                                                                                                                                                                                                                                                                                                
            :funcformat 0                                                                                                                                                                                                                                                                                                                      
            :funccollid 0                                                                                                                                                                                                                                                                                                                      
            :inputcollid 0                                                                                                                                                                                                                                                                                                                     
            :args (                                                                                                                                                                                                                                                                                                                            
               {CONST                                                                                                                                                                                                                                                                                                                          
               :consttype 23                                                                                                                                                                                                                                                                                                                   
               :consttypmod 0                                                                                                                                                                                                                                                                                                                  
               :constcollid 0                                                                                                                                                                                                                                                                                                                  
               :constlen 4                                                                                                                                                                                                                                                                                                                     
               :constbyval true                                                                                                                                                                                                                                                                                                                
               :constisnull false                                                                                                                                                                                                                                                                                                              
               :location -1                                                                                                                                                                                                                                                                                                                    
               :constvalue 4 [ 10 0 0 0 0 0 0 0 ]                                                                                                                                                                                                                                                                                              
               }                                                                                                                                                                                                                                                                                                                               
               {CONST                                                                                                                                                                                                                                                                                                                          
               :consttype 2275                                                                                                                                                                                                                                                                                                                 
               :consttypmod 0                                                                                                                                                                                                                                                                                                                  
               :constcollid 0                                                                                                                                                                                                                                                                                                                  
               :constlen -2                                                                                                                                                                                                                                                                                                                    
               :constbyval false                                                                                                                                                                                                                                                                                                               
               :constisnull true                                                                                                                                                                                                                                                                                                               
               :location -1                                                                                                                                                                                                                                                                                                                    
               :constvalue <>                                                                                                                                                                                                                                                                                                                  
               }                                                                                                                                                                                                                                                                                                                               
               {CONST                                                                                                                                                                                                                                                                                                                          
               :consttype 2275                                                                                                                                                                                                                                                                                                                 
               :consttypmod 0                                                                                                                                                                                                                                                                                                                  
               :constcollid 0                                                                                                                                                                                                                                                                                                                  
               :constlen -2                                                                                                                                                                                                                                                                                                                    
               :constbyval false                                                                                                                                                                                                                                                                                                               
               :constisnull true                                                                                                                                                                                                                                                                                                               
               :location -1                                                                                                                                                                                                                                                                                                                    
               :constvalue <>                                                                                                                                                                                                                                                                                                                  
               }                                                                                                                                                                                                                                                                                                                               
               {CONST                                                                                                                                                                                                                                                                                                                          
               :consttype 2275                                                                                                                                                                                                                                                                                                                 
               :consttypmod 0                                                                                                                                                                                                                                                                                                                  
               :constcollid 0                                                                                                                                                                                                                                                                                                                  
               :constlen -2                                                                                                                                                                                                                                                                                                                    
               :constbyval false                                                                                                                                                                                                                                                                                                               
               :constisnull true                                                                                                                                                                                                                                                                                                               
               :location -1                                                                                                                                                                                                                                                                                                                    
               :constvalue <>                                                                                                                                                                                                                                                                                                                  
               }                                                                                                                                                                                                                                                                                                                               
            )                                                                                                                                                                                                                                                                                                                                  
            :location -1                                                                                                                                                                                                                                                                                                                       
            }                                                                                                                                                                                                                                                                                                                                  
         :funccolcount 3                                                                                                                                                                                                                                                                                                                       
         :funccolnames ("user_id" "sum" "worker_column_3")                                                                                                                                                                                                                                                                                     
         :funccoltypes (o 23 20 23)                                                                                                                                                                                                                                                                                                            
         :funccoltypmods (i -1 -1 -1)                                                                                                                                                                                                                                                                                                          
         :funccolcollations (o 0 0 0)                                                                                                                                                                                                                                                                                                          
         :funcparams (b)                                                                                                                                                                                                                                                                                                                       
         }                                                                                                                                                                                                                                                                                                                                     
      )                                                                                                                                                                                                                                                                                                                                        
      :funcordinality false                                                                                                                                                                                                                                                                                                                    
      :lateral false                                                                                                                                                                                                                                                                                                                           
      :inh false                                                                                                                                                                                                                                                                                                                               
      :inFromCl true                                                                                                                                                                                                                                                                                                                           
      :requiredPerms 0                                                                                                                                                                                                                                                                                                                         
      :checkAsUser 0                                                                                                                                                                                                                                                                                                                           
      :selectedCols (b)                                                                                                                                                                                                                                                                                                                        
      :insertedCols (b)                                                                                                                                                                                                                                                                                                                        
      :updatedCols (b)                                                                                                                                                                                                                                                                                                                         
      :extraUpdatedCols (b)                                                                                                                                                                                                                                                                                                                    
      :securityQuals <>                                                                                                                                                                                                                                                                                                                        
      }                                                                                                                                                                                                                                                                                                                                        
   )                                                                                                                                                                                                                                                                                                                                           
   :jointree                                                                                                                                                                                                                                                                                                                                   
      {FROMEXPR                                                                                                                                                                                                                                                                                                                                
      :fromlist (                                                                                                                                                                                                                                                                                                                              
         {RANGETBLREF                                                                                                                                                                                                                                                                                                                          
         :rtindex 1                                                                                                                                                                                                                                                                                                                            
         }                                                                                                                                                                                                                                                                                                                                     
      )                                                                                                                                                                                                                                                                                                                                        
      :quals <>                                                                                                                                                                                                                                                                                                                                
      }                                                                                                                                                                                                                                                                                                                                        
   :targetList (                                                                                                                                                                                                                                                                                                                               
      {TARGETENTRY                                                                                                                                                                                                                                                                                                                             
      :expr                                                                                                                                                                                                                                                                                                                                    
         {VAR                                                                                                                                                                                                                                                                                                                                  
         :varno 1                                                                                                                                                                                                                                                                                                                              
         :varattno 1                                                                                                                                                                                                                                                                                                                           
         :vartype 23                                                                                                                                                                                                                                                                                                                           
         :vartypmod -1                                                                                                                                                                                                                                                                                                                         
         :varcollid 0                                                                                                                                                                                                                                                                                                                          
         :varlevelsup 0                                                                                                                                                                                                                                                                                                                        
         :varnosyn 1                                                                                                                                                                                                                                                                                                                           
         :varattnosyn 1                                                                                                                                                                                                                                                                                                                        
         :location -1                                                                                                                                                                                                                                                                                                                          
         }                                                                                                                                                                                                                                                                                                                                     
      :resno 1                                                                                                                                                                                                                                                                                                                                 
      :resname user_id                                                                                                                                                                                                                                                                                                                         
      :ressortgroupref 1                                                                                                                                                                                                                                                                                                                       
      :resorigtbl 756471                                                                                                                                                                                                                                                                                                                       
      :resorigcol 1                                                                                                                                                                                                                                                                                                                            
      :resjunk false                                                                                                                                                                                                                                                                                                                           
      }                                                                                                                                                                                                                                                                                                                                        
      {TARGETENTRY                                                                                                                                                                                                                                                                                                                             
      :expr                                                                                                                                                                                                                                                                                                                                    
         {VAR                                                                                                                                                                                                                                                                                                                                  
         :varno 1                                                                                                                                                                                                                                                                                                                              
         :varattno 2                                                                                                                                                                                                                                                                                                                           
         :vartype 20                                                                                                                                                                                                                                                                                                                           
         :vartypmod -1                                                                                                                                                                                                                                                                                                                         
         :varcollid 0                                                                                                                                                                                                                                                                                                                          
         :varlevelsup 0                                                                                                                                                                                                                                                                                                                        
         :varnosyn 1                                                                                                                                                                                                                                                                                                                           
         :varattnosyn 2                                                                                                                                                                                                                                                                                                                        
         :location -1                                                                                                                                                                                                                                                                                                                          
         }                                                                                                                                                                                                                                                                                                                                     
      :resno 2                                                                                                                                                                                                                                                                                                                                 
      :resname sum                                                                                                                                                                                                                                                                                                                             
      :ressortgroupref 2                                                                                                                                                                                                                                                                                                                       
      :resorigtbl 0                                                                                                                                                                                                                                                                                                                            
      :resorigcol 0                                                                                                                                                                                                                                                                                                                            
      :resjunk false                                                                                                                                                                                                                                                                                                                           
      }                                                                                                                                                                                                                                                                                                                                        
      {TARGETENTRY                                                                                                                                                                                                                                                                                                                             
      :expr                                                                                                                                                                                                                                                                                                                                    
         {VAR                                                                                                                                                                                                                                                                                                                                  
         :varno 1                                                                                                                                                                                                                                                                                                                              
         :varattno 3                                                                                                                                                                                                                                                                                                                           
         :vartype 23                                                                                                                                                                                                                                                                                                                           
         :vartypmod -1                                                                                                                                                                                                                                                                                                                         
         :varcollid 0                                                                                                                                                                                                                                                                                                                          
         :varlevelsup 0                                                                                                                                                                                                                                                                                                                        
         :varnosyn 1                                                                                                                                                                                                                                                                                                                           
         :varattnosyn 3                                                                                                                                                                                                                                                                                                                        
         :location -1                                                                                                                                                                                                                                                                                                                          
         }                                                                                                                                                                                                                                                                                                                                     
      :resno 3                                                                                                                                                                                                                                                                                                                                 
      :resname <>                                                                                                                                                                                                                                                                                                                              
      :ressortgroupref 3                                                                                                                                                                                                                                                                                                                       
      :resorigtbl 0                                                                                                                                                                                                                                                                                                                            
      :resorigcol 0                                                                                                                                                                                                                                                                                                                            
      :resjunk true                                                                                                                                                                                                                                                                                                                            
      }                                                                                                                                                                                                                                                                                                                                        
   )                                                                                                                                                                                                                                                                                                                                           
   :override 0                                                                                                                                                                                                                                                                                                                                 
   :onConflict <>                                                                                                                                                                                                                                                                                                                              
   :returningList <>                                                                                                                                                                                                                                                                                                                           
   :groupClause <>                                                                                                                                                                                                                                                                                                                             
   :groupingSets <>                                                                                                                                                                                                                                                                                                                            
   :havingQual <>                                                                                                                                                                                                                                                                                                                              
   :windowClause <>                                                                                                                                                                                                                                                                                                                            
   :distinctClause <>                                                                                                                                                                                                                                                                                                                          
   :sortClause (                                                                                                                                                                                                                                                                                                                               
      {SORTGROUPCLAUSE                                                                                                                                                                                                                                                                                                                         
      :tleSortGroupRef 1                                                                                                                                                                                                                                                                                                                       
      :eqop 96                                                                                                                                                                                                                                                                                                                                 
      :sortop 97                                                                                                                                                                                                                                                                                                                               
      :nulls_first false                                                                                                                                                                                                                                                                                                                       
      :hashable true                                                                                                                                                                                                                                                                                                                           
      }                                                                                                                                                                                                                                                                                                                                        
      {SORTGROUPCLAUSE                                                                                                                                                                                                                                                                                                                         
      :tleSortGroupRef 2                                                                                                                                                                                                                                                                                                                       
      :eqop 410                                                                                                                                                                                                                                                                                                                                
      :sortop 412                                                                                                                                                                                                                                                                                                                              
      :nulls_first false                                                                                                                                                                                                                                                                                                                       
      :hashable true                                                                                                                                                                                                                                                                                                                           
      }                                                                                                                                                                                                                                                                                                                                        
   )                                                                                                                                                                                                                                                                                                                                           
   :limitOffset <>                                                                                                                                                                                                                                                                                                                             
   :limitCount                                                                                                                                                                                                                                                                                                                                 
      {CONST                                                                                                                                                                                                                                                                                                                                   
      :consttype 20                                                                                                                                                                                                                                                                                                                            
      :consttypmod -1                                                                                                                                                                                                                                                                                                                          
      :constcollid 0                                                                                                                                                                                                                                                                                                                           
      :constlen 8                                                                                                                                                                                                                                                                                                                              
      :constbyval true                                                                                                                                                                                                                                                                                                                         
      :constisnull false                                                                                                                                                                                                                                                                                                                       
      :location -1                                                                                                                                                                                                                                                                                                                             
      :constvalue 8 [ 5 0 0 0 0 0 0 0 ]                                                                                                                                                                                                                                                                                                        
      }                                                                                                                                                                                                                                                                                                                                        
   :limitOption 0                                                                                                                                                                                                                                                                                                                              
   :rowMarks <>                                                                                                                                                                                                                                                                                                                                
   :setOperations <>                                                                                                                                                                                                                                                                                                                           
   :constraintDeps <>                                                                                                                                                                                                                                                                                                                          
   :withCheckOptions <>                                                                                                                                                                                                                                                                                                                        
   :stmt_location 0                                                                                                                                                                                                                                                                                                                            
   :stmt_len 0                                                                                                                                                                                                                                                                                                                                 
   }                                                                                                                                                                                                                                                                                                                                           

PG 12.5, Citus master, extra "sum":

NOTICE:     {QUERY                                     
   :commandType 1                                           
   :querySource 0                                           
   :canSetTag true                                          
   :utilityStmt <>                                                                                                                    
   :resultRelation 0                                        
   :hasAggs false                                                  
   :hasWindowFuncs false                                           
   :hasTargetSRFs false                                            
   :hasSubLinks false                                              
   :hasDistinctOn false                                            
   :hasRecursive false                                             
   :hasModifyingCTE false                                          
   :hasForUpdate false                                             
   :hasRowSecurity false                                           
   :cteList <>                                                     
   :rtable (                                                              
      {RTE                                                                
      :alias <>                                                           
      :eref                                                                        
         {ALIAS                                                                    
         :aliasname remote_scan                                                    
         :colnames ("user_id" "sum" "worker_column_3")                                                                                                                                                                         
         }                                                                         
      :rtekind 3                                                                   
      :functions (                                                                 
         {RANGETBLFUNCTION                                                         
         :funcexpr                                                                 
            {FUNCEXPR                                                              
            :funcid 397379                                                         
            :funcresulttype 2249                                                   
            :funcretset true                                                       
            :funcvariadic false                                                    
            :funcformat 0                                                                      
            :funccollid 0                                                                      
            :inputcollid 0                                                                     
            :args (                                                                            
               {CONST                                                                          
               :consttype 23                                                                   
               :consttypmod 0                                                                  
               :constcollid 0                                                                  
               :constlen 4                                                                     
               :constbyval true                                                                
               :constisnull false                                                              
               :location -1                                                                                    
               :constvalue 4 [ 10 0 0 0 0 0 0 0 ]                                                              
               }                                                                                               
               {CONST                                                                                          
               :consttype 2275                                                                                 
               :consttypmod 0                                                                                  
               :constcollid 0                                                                                  
               :constlen -2                                                                                    
               :constbyval false                                                                               
               :constisnull true                                                                               
               :location -1                                                                                    
               :constvalue <>                                                                                  
               }                                                                                               
               {CONST                                                                                          
               :consttype 2275                                                                                 
               :consttypmod 0                                                                                  
               :constcollid 0                                                                                  
               :constlen -2                                                                                    
               :constbyval false                                                                               
               :constisnull true                                                                               
               :location -1                                                                                    
               :constvalue <>                                                                                  
               }                                                                                               
               {CONST                                                                                                                 
               :consttype 2275                                                                                                        
               :consttypmod 0                                                                                                         
               :constcollid 0                                                                                                         
               :constlen -2                                                                                                           
               :constbyval false                                                                                                      
               :constisnull true                                                                                                      
               :location -1                                                                                                           
               :constvalue <>                                                                                                         
               }                                                                                                                      
            )                                                                                                                         
            :location -1                                                                                                              
            }                                                                                                                         
         :funccolcount 4                                                                                                              
         :funccolnames ("user_id" "sum" "worker_column_3" "sum")                                                                      
         :funccoltypes (o 23 20 23 20)                                                                                                
         :funccoltypmods (i -1 -1 -1 -1)                                                                                              
         :funccolcollations (o 0 0 0 0)                                                                                               
         :funcparams (b)                                                                                                              
         }                                                                                                                            
      )                                                                                                                               
      :funcordinality false                                                                                                           
      :lateral false                                                                                                                                                   
      :inh false                                                                                                                                                       
      :inFromCl true                                                                                                                                                   
      :requiredPerms 0                                                                                                                                                 
      :checkAsUser 0                                                                                                                                                   
      :selectedCols (b)                                                                                                                                                
      :insertedCols (b)                                                                                                                                                
      :updatedCols (b)                                                                                                                                                 
      :extraUpdatedCols (b)                                                                                                                                            
      :securityQuals <>                                                                                                                                                
      }                                                                                                                                                                
   )                                                                                                                                                                   
   :jointree                                                                                                                                                           
      {FROMEXPR                                                                                                                                                        
      :fromlist (                                                                                                                                                      
         {RANGETBLREF                                                                                                                                                  
         :rtindex 1                                                                                                                                                    
         }                                                                                                                                                             
      )                                                                                                                                                                
      :quals <>                                                                                                                                                        
      }                                                                                                                                                                
   :targetList (                                                                                                                                                       
      {TARGETENTRY                                                                                                                                                     
      :expr                                                                                                                                                            
         {VAR                                                                                                                                                          
         :varno 1                                                                                                                                                      
         :varattno 1                                                                                                                                                   
         :vartype 23                                                                                                                                                   
         :vartypmod -1                                                                                                                                                 
         :varcollid 0                                                                                                                                                  
         :varlevelsup 0                                                                                                                                                
         :varnoold 1                                                                                                                                                   
         :varoattno 1                                                                                                                                                  
         :location -1                                                                                                                                                  
         }                                                                                                                                                             
      :resno 1                                                                                                                                                         
      :resname user_id                                                                                                                                                 
      :ressortgroupref 1                                                                                                                                               
      :resorigtbl 397521                                                                                                                                               
      :resorigcol 1                                                                                                                                                    
      :resjunk false                                                                                                                                                   
      }                                                                                                                                                                
      {TARGETENTRY                                                                                                                                                     
      :expr                                                                                                                                                            
         {VAR                                                                                                                                                          
         :varno 1                                                                                                                                                      
         :varattno 2                                                                                                                                                   
         :vartype 20                                                                                                                                                   
         :vartypmod -1                                                                                                                                                 
         :varcollid 0                                                                                                                                                  
         :varlevelsup 0                                                                                                                                                
         :varnoold 1                                                                                                                                                                                                           
         :varoattno 2                                                                                                                                                                                                          
         :location -1                                                                                                                                                                                                          
         }                                                                                                                                                                                                                     
      :resno 2                                                                                                                                                                                                                 
      :resname sum                                                                                                                                                                                                             
      :ressortgroupref 2                                                                                                                                                                                                       
      :resorigtbl 0                                                                                                                                                                                                            
      :resorigcol 0                                                                                                                                                                                                            
      :resjunk false                                                                                                                                                                                                           
      }                                                                                                                                                                                                                        
      {TARGETENTRY                                                                                                                                                                                                             
      :expr                                                                                                                                                                                                                    
         {VAR                                                                                                                                                                                                                  
         :varno 1                                                                                                                                                                                                              
         :varattno 3                                                                                                                                                                                                           
         :vartype 23                                                                                                                                                                                                           
         :vartypmod -1                                                                                                                                                                                                         
         :varcollid 0                                                                                                                                                                                                          
         :varlevelsup 0                                                                                                                                                                                                        
         :varnoold 1                                                                                                                                                                                                           
         :varoattno 3                                                                                                                                                                                                          
         :location -1                                                                                                                                                                                                          
         }                                                                                                                                                                                                                     
      :resno 3                                                                                                                                                                                                                 
      :resname <>                                                                                                                                                                                                              
      :ressortgroupref 3                                                                                                                                                                                                       
      :resorigtbl 0                                                                                                                                                                                                            
      :resorigcol 0                                                                                                                                                                                                            
      :resjunk true                                                                                                                                                                                                            
      }                                                                                                                                                                                                                        
   )                                                                                                                                                                                                                           
   :override 0                                                                                                                                                                                                                 
   :onConflict <>                                                                                                                                                                                                              
   :returningList <>                                                                                                                                                                                                           
   :groupClause <>                                                                                                                                                                                                             
   :groupingSets <>                                                                                                                                                                                                            
   :havingQual <>                                                                                                                                                                                                              
   :windowClause <>                                                                                                                                                                                                            
   :distinctClause <>                                                                                                                                                                                                          
   :sortClause (                                                                                                                                                                                                               
      {SORTGROUPCLAUSE                                                                                                                                                                                                         
      :tleSortGroupRef 1                                                                                                                                                                                                       
      :eqop 96                                                                                                                                                                                                                 
      :sortop 97                                                                                                                                                                                                               
      :nulls_first false                                                                                                                                                                                                       
      :hashable true                                                                                                                                                                                                           
      }                                                                                                                                                                                                                        
      {SORTGROUPCLAUSE                                                                                                                                                                                                         
      :tleSortGroupRef 2                                                                                                                                                                                                       
      :eqop 410                                                                                                                                                                                                                
      :sortop 412                                                                                                                                                                                                              
      :nulls_first false                                                                                                                                                                                                       
      :hashable true                                                                                                                                                                                                           
      }                                                                                                                                                                                                                        
   )                                                                                                                                                                                                                           
   :limitOffset <>                                                                                                                                                                                                             
   :limitCount                                                                                                                                                                                                                 
      {CONST                                                                                                                                                                                                                   
      :consttype 20                                                                                                                                                                                                            
      :consttypmod -1                                                                                                                                                                                                          
      :constcollid 0                                                                                                                                                                                                           
      :constlen 8                                                                                                                                                                                                              
      :constbyval true                                                                                                                                                                                                         
      :constisnull false                                                                                                                                                                                                       
      :location -1                                                                                                                                                                                                             
      :constvalue 8 [ 5 0 0 0 0 0 0 0 ]                                                                                                                                                                                        
      }                                                                                                                                                                                                                        
   :rowMarks <>                                                                                                                                                                                                                
   :setOperations <>                                                                                                                                                                                                           
   :constraintDeps <>                                                                                                                                                                                                          
   :withCheckOptions <>                                                                                                                                                                                                        
   :stmt_location 0                                                                                                                                                                                                            
   :stmt_len 0                                                                                                                                                                                                                 
   }                                  

@agedemenli
Copy link
Contributor

create table users_table (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint);
select create_distributed_table('users_table', 'user_id');

create table events_table (user_id int, time timestamp, event_type int, value_2 int, value_3 float, value_4 bigint);
select create_distributed_table('events_table', 'user_id');


insert into users_table select i % 10000, timestamp '2014-01-10 20:00:00' +
       i * (timestamp '2014-01-20 20:00:00' -
                   timestamp '2014-01-10 10:00:00'),i, i % 100, i % 5 from generate_series(0, 1000) i;


insert into events_table select i % 10000, timestamp '2014-01-10 20:00:00' +
       i * (timestamp '2014-01-20 20:00:00' -
                   timestamp '2014-01-10 10:00:00'),i, i % 100, i % 5 from generate_series(0, 10000) i;

set log_min_messages=debug4;

SELECT
	user_id, rank() OVER my_win as rnk, avg(value_2) as avg_val_2
FROM
	events_table
GROUP BY
	user_id, date_trunc('day', time)
WINDOW
	my_win AS (PARTITION BY user_id ORDER BY avg(event_type) DESC)
ORDER BY
	3 DESC, 2 DESC, 1 DESC;

This also crashes even when the result of GenerateNewTargetEntriesForSortClauses is ignored.

@agedemenli
Copy link
Contributor

Another case that crashes with DEBUG4:

SET log_min_messages TO DEBUG4;

CREATE TABLE reference_table(id int PRIMARY KEY);
SELECT create_reference_table('reference_table');

CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time);

SELECT create_distributed_table('partitioning_test', 'id');

ALTER TABLE partitioning_test ADD CONSTRAINT partitioning_reference_fkey
     FOREIGN KEY (id) REFERENCES reference_table(id) ON DELETE CASCADE;

DROP TABLE reference_table, partitioning_test;

@agedemenli
Copy link
Contributor

DROP TABLE reference_table CASCADE; also triggers the crash

@agedemenli
Copy link
Contributor

The crash happens on relation_access_tracking.c, on line: 788, here:

ereport(DEBUG1, (errmsg("switching to sequential query execution mode"),
		 errdetail(
			 "Table \"%s\" is modified, which might lead to data "
			 "inconsistencies or distributed deadlocks via "
			 "parallel accesses to hash distributed tables due to "
			 "foreign keys. Any parallel modification to "
			 "those hash distributed tables in the same "
			 "transaction can only be executed in sequential query "
			 "execution mode", relationName)));

This crashes not only for DEBUG4, but also other DEBUG levels.
The reason for that is, even the relationId for reference_table is correct, however, char *relationName = get_rel_name(relationId); on line 762 returns NULL for some reason. Then it leads to crash while trying to print a NULL string.

@agedemenli
Copy link
Contributor

Both 2 bugs are fixed. It seems there's no other crashing case. Closing the issue.

@hanefi
Copy link
Member

hanefi commented Jul 10, 2021

@agedemenli can you share the set of PRs/commits that should be backported to 10.0 releases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants