Repository: citusdata/citus

Issue #3808: Assertion Failure in SubqueryColocated Function
Created: 2020-04-29T10:59:53Z
Query is generated by SQLSmith
select  
  sample_0.org_id as c0, 
  sample_0.id as c1, 
  sample_0.user_id as c2, 
  6 as c3, 
  pg_catalog.pg_client_encoding() as c4
from 
  public.events as sample_0 tablesample system (1) 
where (EXISTS (
    select  
        sample_0.org_id as c0
      from 
        public.orders as ref_0
      where (cast(null as record) *> cast(nullif(cast(null as record),
            cast(null as record)) as record)) 
        and ((true) 
          or (sample_0.org_id is NULL))
      limit 13)) 
  or (((case when cast(null as bpchar) > cast(null as bpchar) then cast(null as tsquery) else cast(null as tsquery) end
           @@ cast(null as tsvector)) 
      and (EXISTS (
        select  
            sample_0.event_type as c0, 
            sample_0.id as c1
          from 
            public.orders as sample_1 tablesample system (5.4) 
              left join public.countries as sample_2 tablesample bernoulli (0.6) 
              on ((cast(null as macaddr) < cast(null as macaddr)) 
                  and (cast(null as int2) >= cast(null as int2)))
          where cast(null as money) >= cast(null as money)
          limit 97))) 
    or (EXISTS (
      select  
          pg_catalog.pg_stat_get_bgwriter_requested_checkpoints() as c0
        from 
          public.orders as sample_3 tablesample system (6.3) 
        where ((true) 
            or (sample_0.payload is NULL)) 
          and (sample_0.org_id is NULL)
        limit 51)))
limit 168;

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007f8fcef32801 in __GI_abort () at abort.c:79
#2  0x000055dd9d34bafb in ExceptionalCondition (conditionName=conditionName@entry=0x7f8fcc3be8a0 "!(!FindNodeCheck((Node *) subquery, IsDistributedTableRTE))",
    errorType=errorType@entry=0x7f8fcc3a3f00 "FailedAssertion", fileName=fileName@entry=0x7f8fcc3be878 "planner/query_colocation_checker.c",
    lineNumber=lineNumber@entry=198) at assert.c:54
#3  0x00007f8fcc3707e4 in SubqueryColocated (subquery=subquery@entry=0x55dd9edc5360, checker=checker@entry=0x7ffd9a328670)
    at planner/query_colocation_checker.c:198
#4  0x00007f8fcc37353c in RecursivelyPlanNonColocatedSubqueriesInWhere (query=query@entry=0x55dd9ed619c8,
    colocatedJoinChecker=colocatedJoinChecker@entry=0x7ffd9a328670, recursivePlanningContext=recursivePlanningContext@entry=0x7ffd9a328700)
    at planner/recursive_planning.c:562
#5  0x00007f8fcc3735d8 in RecursivelyPlanNonColocatedSubqueries (subquery=subquery@entry=0x55dd9ed619c8, context=context@entry=0x7ffd9a328700)
    at planner/recursive_planning.c:453
#6  0x00007f8fcc3739c9 in RecursivelyPlanSubqueriesAndCTEs (query=query@entry=0x55dd9ed619c8, context=context@entry=0x7ffd9a328700)
    at planner/recursive_planning.c:340
#7  0x00007f8fcc373a8e in GenerateSubplansForSubqueriesAndCTEs (planId=planId@entry=5, originalQuery=originalQuery@entry=0x55dd9ed619c8,
    plannerRestrictionContext=plannerRestrictionContext@entry=0x55dd9ee2db80) at planner/recursive_planning.c:228
#8  0x00007f8fcc3576bc in CreateDistributedPlan (planId=planId@entry=5, originalQuery=0x55dd9ed619c8, query=0x55dd9ed61ae0, boundParams=0x0,
    hasUnresolvedParams=hasUnresolvedParams@entry=false, plannerRestrictionContext=0x55dd9ee2db80) at planner/distributed_planner.c:1018
#9  0x00007f8fcc3580aa in CreateDistributedPlannedStmt (planContext=planContext@entry=0x7ffd9a328860) at planner/distributed_planner.c:703
#10 0x00007f8fcc3584c3 in PlanDistributedStmt (planContext=planContext@entry=0x7ffd9a328860, rteIdCounter=<optimized out>, rteIdCounter@entry=6)
    at planner/distributed_planner.c:635
#11 0x00007f8fcc35882e in distributed_planner (parse=0x55dd9ed61ae0, cursorOptions=256, boundParams=0x0) at planner/distributed_planner.c:262
#12 0x000055dd9d1466bd in planner (parse=parse@entry=0x55dd9ed61ae0, cursorOptions=cursorOptions@entry=256, boundParams=boundParams@entry=0x0) at planner.c:273
#13 0x000055dd9d214c4c in pg_plan_query (querytree=querytree@entry=0x55dd9ed61ae0, cursorOptions=cursorOptions@entry=256, boundParams=boundParams@entry=0x0)
    at postgres.c:878
#14 0x000055dd9d214d96 in pg_plan_queries (querytrees=<optimized out>, cursorOptions=cursorOptions@entry=256, boundParams=boundParams@entry=0x0)
    at postgres.c:968
#15 0x000055dd9d215110 in exec_simple_query (
    query_string=query_string@entry=0x55dd9ebef3a8 "select  \n  sample_0.org_id as c0, \n  sample_0.id as c1, \n  sample_0.user_id as c2, \n  6 as c3, \n  pg_catalog.pg_client_encoding() as c4\nfrom \n  public.events as sample_0 tablesample system (1) \nwhere "...) at postgres.c:1143
#16 0x000055dd9d2172f0 in PostgresMain (argc=<optimized out>, argv=argv@entry=0x55dd9ec87b98, dbname=<optimized out>, username=<optimized out>)
    at postgres.c:4236
#17 0x000055dd9d186601 in BackendRun (port=port@entry=0x55dd9ec85690) at postmaster.c:4437
#18 0x000055dd9d189a48 in BackendStartup (port=port@entry=0x55dd9ec85690) at postmaster.c:4128
#19 0x000055dd9d189d62 in ServerLoop () at postmaster.c:1704
#20 0x000055dd9d18b164 in PostmasterMain (argc=5, argv=<optimized out>) at postmaster.c:1377
#21 0x000055dd9d0e1fbf in main (argc=5, argv=0x55dd9ebe68a0) at main.c:228

Duplicate issue #3753: Assertion failure with non-colocated subquery joins
Created: 2020-04-14T13:08:12Z
Generated by SQLSmith
select  
  subq_0.c5 as c0
from 
  (select  
        sample_0.value_3 as c0, 
        case when cast(null as macaddr8) >= cast(null as macaddr8) then sample_0.time else sample_0.time end
           as c1, 
        sample_0.value_2 as c2, 
        sample_0.user_id as c3, 
        sample_0.value_3 as c4, 
        sample_0.x as c5, 
        96 as c6, 
        sample_0.x as c7, 
        sample_0.user_id as c8, 
        (select colocationid from citus.pg_dist_object limit 1 offset 1)
           as c9
      from 
        public.users_table as sample_0 tablesample system (3.7) 
      where (58 is NULL) 
        and (cast(null as box) &> cast(null as box))) as subq_0
where cast(nullif(case when case when (cast(null as box) >^ cast(null as box)) 
            and (true) then case when (cast(null as date) < cast(null as timestamptz)) 
              and (cast(null as tsvector) > cast(null as tsvector)) then cast(null as money) else cast(null as money) end
             else case when (cast(null as date) < cast(null as timestamptz)) 
              and (cast(null as tsvector) > cast(null as tsvector)) then cast(null as money) else cast(null as money) end
             end
           >= case when (EXISTS (
              select  
                  sample_1.object_args as c0, 
                  (select time from public.users_table limit 1 offset 6)
                     as c1, 
                  sample_1.object_args as c2, 
                  subq_0.c1 as c3, 
                  subq_0.c9 as c4, 
                  subq_0.c4 as c5, 
                  sample_1.object_names as c6, 
                  subq_0.c5 as c7, 
                  sample_1.object_names as c8, 
                  subq_0.c6 as c9, 
                  sample_1.classid as c10, 
                  sample_1.type as c11
                from 
                  citus.pg_dist_object as sample_1 tablesample system (8.9) 
                where false
                limit 37)) 
            or (((cast(null as oidvector) > cast(null as oidvector)) 
                and (subq_0.c1 is NULL)) 
              and (false)) then cast(null as money) else cast(null as money) end
           then case when pg_catalog.pg_my_temp_schema() = (select classid from citus.pg_dist_object limit 1 offset 2)
             then cast(null as date) else cast(null as date) end
         else case when pg_catalog.pg_my_temp_schema() = (select classid from citus.pg_dist_object limit 1 offset 2)
             then cast(null as date) else cast(null as date) end
         end
      ,
    cast(null as date)) as date) <> case when pg_catalog.poly_center(
        cast(case when subq_0.c4 is not NULL then cast(null as polygon) else cast(null as polygon) end
           as polygon)) << pg_catalog.point(
        cast(case when false then cast(null as polygon) else cast(null as polygon) end
           as polygon)) then case when ((cast(null as jsonb) <= cast(null as jsonb)) 
          or ((subq_0.c8 is not NULL) 
            or (cast(null as line) ?-| cast(null as line)))) 
        or (EXISTS (
          select  
              subq_0.c8 as c0, 
              subq_0.c5 as c1, 
              ref_1.y as c2, 
              ref_0.event_type as c3, 
              ref_0.value_4 as c4, 
              ref_1.value_4 as c5, 
              subq_0.c5 as c6
            from 
              public.events_table_ref as ref_0
                inner join public.users_table as ref_1
                on ((select event_type from public.events_table limit 1 offset 5)
                       is NULL)
            where ((select value_4 from public.events_table_ref limit 1 offset 90)
                   >= cast(null as int2)) 
              and (EXISTS (
                select  
                    ref_1.value_4 as c0, 
                    ref_1.x as c1, 
                    subq_0.c9 as c2, 
                    ref_2.value_4 as c3, 
                    subq_0.c4 as c4, 
                    ref_0.time as c5, 
                    ref_1.value_2 as c6, 
                    ref_1.user_id as c7, 
                    ref_0.time as c8
                  from 
                    public.events_table_ref as ref_2
                  where EXISTS (
                    select  
                        ref_1.value_2 as c0, 
                        ref_0.user_id as c1
                      from 
                        public.events_table_ref as ref_3
                      where cast(null as "char") = cast(null as "char"))
                  limit 97))
            limit 147)) then cast(nullif(cast(nullif(case when cast(null as bytea) < cast(null as bytea) then cast(null as date) else cast(null as date) end
            ,
          cast(null as date)) as date),
        cast(null as date)) as date) else cast(nullif(cast(nullif(case when cast(null as bytea) < cast(null as bytea) then cast(null as date) else cast(null as date) end
            ,
          cast(null as date)) as date),
        cast(null as date)) as date) end
       else case when ((cast(null as jsonb) <= cast(null as jsonb)) 
          or ((subq_0.c8 is not NULL) 
            or (cast(null as line) ?-| cast(null as line)))) 
        or (EXISTS (
          select  
              subq_0.c8 as c0, 
              subq_0.c5 as c1, 
              ref_1.y as c2, 
              ref_0.event_type as c3, 
              ref_0.value_4 as c4, 
              ref_1.value_4 as c5, 
              subq_0.c5 as c6
            from 
              public.events_table_ref as ref_0
                inner join public.users_table as ref_1
                on ((select event_type from public.events_table limit 1 offset 5)
                       is NULL)
            where ((select value_4 from public.events_table_ref limit 1 offset 90)
                   >= cast(null as int2)) 
              and (EXISTS (
                select  
                    ref_1.value_4 as c0, 
                    ref_1.x as c1, 
                    subq_0.c9 as c2, 
                    ref_2.value_4 as c3, 
                    subq_0.c4 as c4, 
                    ref_0.time as c5, 
                    ref_1.value_2 as c6, 
                    ref_1.user_id as c7, 
                    ref_0.time as c8
                  from 
                    public.events_table_ref as ref_2
                  where EXISTS (
                    select  
                        ref_1.value_2 as c0, 
                        ref_0.user_id as c1
                      from 
                        public.events_table_ref as ref_3
                      where cast(null as "char") = cast(null as "char"))
                  limit 97))
            limit 147)) then cast(nullif(cast(nullif(case when cast(null as bytea) < cast(null as bytea) then cast(null as date) else cast(null as date) end
            ,
          cast(null as date)) as date),
        cast(null as date)) as date) else cast(nullif(cast(nullif(case when cast(null as bytea) < cast(null as bytea) then cast(null as date) else cast(null as date) end
            ,
          cast(null as date)) as date),
        cast(null as date)) as date) end
       end
    ;
* thread #1, stop reason = signal SIGSTOP
  * frame #0: 0x00007fff7e0af2c2 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff7e16abf1 libsystem_pthread.dylib`pthread_kill + 284
    frame #2: 0x00007fff7e0196a6 libsystem_c.dylib`abort + 127
    frame #3: 0x000000010418c0ee postgres`ExceptionalCondition(conditionName=<unavailable>, errorType=<unavailable>, fileName=<unavailable>, lineNumber=<unavailable>) at assert.c:54:2
    frame #4: 0x0000000106869091 citus.so`SubqueryColocated(subquery=<unavailable>, checker=<unavailable>) at query_colocation_checker.c:198:3
    frame #5: 0x000000010686bfb7 citus.so`RecursivelyPlanNonColocatedSubqueriesInWhere(query=<unavailable>, colocatedJoinChecker=0x00007ffeebf04010, recursivePlanningContext=0x00007ffeebf04090) at recursive_planning.c:562:8
    frame #6: 0x000000010686b760 citus.so`RecursivelyPlanNonColocatedSubqueries(subquery=0x0000000106a10498, context=0x00007ffeebf04090) at recursive_planning.c:453:2
    frame #7: 0x000000010686ab4f citus.so`RecursivelyPlanSubqueriesAndCTEs(query=0x0000000106a10498, context=0x00007ffeebf04090) at recursive_planning.c:340:3
    frame #8: 0x000000010686a9aa citus.so`GenerateSubplansForSubqueriesAndCTEs(planId=99, originalQuery=0x0000000106a10498, plannerRestrictionContext=<unavailable>) at recursive_planning.c:228:32
    frame #9: 0x0000000106852d23 citus.so`CreateDistributedPlan(planId=99, originalQuery=0x0000000106a10498, query=0x0000000106a105b0, boundParams=0x0000000000000000, hasUnresolvedParams=<unavailable>, plannerRestrictionContext=0x0000000106b3aff8) at distributed_planner.c:1019:22
    frame #10: 0x00000001068529ca citus.so`CreateDistributedPlannedStmt(planContext=0x00007ffeebf041c0) at distributed_planner.c:705:3
    frame #11: 0x000000010685196e citus.so`PlanDistributedStmt(planContext=0x00007ffeebf041c0, rteIdCounter=<unavailable>) at distributed_planner.c:636:24
    frame #12: 0x00000001068514b0 citus.so`distributed_planner(parse=0x0000000106a105b0, cursorOptions=<unavailable>, boundParams=<unavailable>) at distributed_planner.c:263:14
    frame #13: 0x0000000103fc5088 postgres`pg_plan_query(querytree=0x0000000106a105b0, cursorOptions=256, boundParams=0x0000000000000000) at postgres.c:832:9
    frame #14: 0x0000000103fc51ae postgres`pg_plan_queries(querytrees=<unavailable>, cursorOptions=256, boundParams=0x0000000000000000) at postgres.c:898:11
    frame #15: 0x0000000103fc6efe postgres`exec_simple_query(query_string="select  \n  subq_0.c5 as c0\nfrom \n  (select  \n        sample_0.value_3 as c0, \n        case when cast(null as macaddr8) >= cast(null as macaddr8) then sample_0.time else sample_0.time end\n           as c1, \n        sample_0.value_2 as c2, \n        sample_0.user_id as c3, \n        sample_0.value_3 as c4, \n        sample_0.x as c5, \n        96 as c6, \n        sample_0.x as c7, \n        sample_0.user_id as c8, \n        (select colocationid from citus.pg_dist_object limit 1 offset 1)\n           as c9\n      from \n        public.users_table as sample_0 tablesample system (3.7) \n      where (58 is NULL) \n        and (cast(null as box) &> cast(null as box))) as subq_0\nwhere cast(nullif(case when case when (cast(null as box) >^ cast(null as box)) \n            and (true) then case when (cast(null as date) < cast(null as timestamptz)) \n              and (cast(null as tsvector) > cast(null as tsvector)) then cast(null as money) else cast(null as money) end\n             else case when (cast(null as date) < cast(null as tim"...) at postgres.c:1073:19
    frame #16: 0x0000000103fc6784 postgres`PostgresMain(argc=<unavailable>, argv=<unavailable>, dbname=<unavailable>, username=<unavailable>) at postgres.c:0
    frame #17: 0x0000000103f55096 postgres`BackendRun(port=0x00000001043043be) at postmaster.c:4364:2
    frame #18: 0x0000000103f5491f postgres`BackendStartup(port=<unavailable>) at postmaster.c:4036:3
    frame #19: 0x0000000103f540d5 postgres`ServerLoop at postmaster.c:1707:7
    frame #20: 0x0000000103f5221a postgres`PostmasterMain(argc=3, argv=0x00007f88b9c03150) at postmaster.c:1380:11
    frame #21: 0x0000000103ec1cf6 postgres`main(argc=3, argv=0x00007f88b9c03150) at main.c:228:3
    frame #22: 0x00007fff7df743d5 libdyld.dylib`start + 1
    frame #23: 0x00007fff7df743d5 libdyld.dylib`start + 1

Closing comment (2020-05-01T11:56:47Z): same as #3808