citusdata / citusdata/citus

Citus unnecessarily errors out for some expressions with COLLATION on target list

Open
#3,982 2 comments 0 reactions 0 assignees View on GitHub
bug sqlancer
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

Generated by SQLancer (not fixed by #3973 but could be similar). When `COLLATE "C"` is removed from the query, it works fine.

```SQL

CREATE UNLOGGED TABLE IF NOT EXISTS t0(
c0 FLOAT UNIQUE PRIMARY KEY DEFAULT (0.29820135079960586),
c1 BIGSERIAL);

-- same query on Postgres works fine
SELECT MAX(CAST(0.800353 AS MONEY)), ('' COLLATE "C")
FROM ONLY t0
GROUP BY t0.c1
HAVING (MAX(CAST(0.5828514 AS MONEY))) IS NOT NULL
UNION ALL
SELECT MAX((0.800353)::MONEY), ('')
FROM ONLY t0
GROUP BY t0.c1
HAVING NOT ((MAX((0.5828514)::MONEY)) IS NOT NULL)
UNION ALL
SELECT ALL MAX(CAST(0.800353 AS MONEY)), ('')
FROM ONLY t0
GROUP BY t0.c1
HAVING ((MAX((0.5828514)::MONEY)) IS NOT NULL) IS NULL;
(0 rows)

SELECT create_distributed_table('t0', 'c0');

-- fails on Citus
SELECT MAX(CAST(0.800353 AS MONEY)), ('' COLLATE "C")
FROM ONLY t0
GROUP BY t0.c1
HAVING (MAX(CAST(0.5828514 AS MONEY))) IS NOT NULL
UNION ALL
SELECT MAX((0.800353)::MONEY), ('')
FROM ONLY t0
GROUP BY t0.c1
HAVING NOT ((MAX((0.5828514)::MONEY)) IS NOT NULL)
UNION ALL
SELECT ALL MAX(CAST(0.800353 AS MONEY)), ('')
FROM ONLY t0
GROUP BY t0.c1
HAVING ((MAX((0.5828514)::MONEY)) IS NOT NULL) IS NULL;
ERROR: failed to find conversion function from unknown to text
```

The backtrace:
```
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x000000010b743467 postgres`errstart(elevel=20, filename="parse_coerce.c", lineno=530, funcname="coerce_type", domain=0x0000000000000000) at elog.c:263:14
frame #1: 0x000000010b745621 postgres`elog_finish(elevel=20, fmt="failed to find conversion function from %s to %s") at elog.c:1337:7
frame #2: 0x000000010b7ab05d postgres`coerce_type.cold.1 + 77
frame #3: 0x000000010b478e0d postgres`coerce_type(pstate=, node=, inputTypeId=, targetTypeId=, targetTypeMod=, ccontext=, cformat=COERCE_IMPLICIT_CAST, location=-1) at parse_coerce.c:529:2
frame #4: 0x000000010b479e84 postgres`coerce_to_common_type(pstate=0x0000000000000000, node=0x000000010e73dd08, targetTypeId=25, context="UNION/INTERSECT/EXCEPT") at parse_coerce.c:1412:10
frame #5: 0x000000010b5b7673 postgres`generate_setop_tlist(colTypes=, colCollations=, flag=-1, varno=1, hack_constants=, input_tlist=, refnames_tlist=0x000000010e738848) at prepunion.c:1180:11
frame #6: 0x000000010b5b71f2 postgres`recurse_set_operations(setOp=0x000000010e73ae00, root=0x000000010e73b3d0, colTypes=0x000000010e73b020, colCollations=0x000000010e73b130, junkOK=, flag=-1, refnames_tlist=0x000000010e738848, pTargetList=0x00007ffee4885ce0, pNumGroups=0x0000000000000000) at prepunion.c:249:11
frame #7: 0x000000010b5b7ffe postgres`plan_union_children(root=0x000000010e73b3d0, top_union=0x000000010e73ad50, refnames_tlist=0x000000010e738848, tlist_list=0x00007ffee4885d30) at prepunion.c:915:28
frame #8: 0x000000010b5b788c postgres`generate_union_paths(op=0x000000010e73ad50, root=0x000000010e73b3d0, refnames_tlist=0x000000010e738848, pTargetList=0x00007ffee4885e20) at prepunion.c:573:12
frame #9: 0x000000010b5b7315 postgres`recurse_set_operations(setOp=, root=0x000000010e73b3d0, colTypes=0x000000010e73b020, colCollations=0x000000010e73b130, junkOK=, flag=-1, refnames_tlist=0x000000010e738848, pTargetList=0x00007ffee4885e20, pNumGroups=0x0000000000000000) at prepunion.c:347:10
frame #10: 0x000000010b5b6dba postgres`plan_set_operations(root=0x000000010e73b3d0) at prepunion.c:165:15
frame #11: 0x000000010b5a72b7 postgres`grouping_planner(root=0x000000010e73b3d0, inheritance_update=, tuple_fraction=) at planner.c:1876:17
frame #12: 0x000000010b5a5d4b postgres`subquery_planner(glob=, parse=0x000000010e737be0, parent_root=, hasRecursion=, tuple_fraction=0) at planner.c:1012:3
frame #13: 0x000000010b5a5068 postgres`standard_planner(parse=0x000000010e737be0, cursorOptions=0, boundParams=0x0000000000000000) at planner.c:406:9
frame #14: 0x000000010dfe0fd1 citus.so`CreateDistributedPlan(planId=36, originalQuery=0x00007fefa10945b0, query=0x00007fefa10946c8, boundParams=0x0000000000000000, hasUnresolvedParams=, plannerRestrictionContext=0x00007fefa10a6770) at distributed_planner.c:1026:3
frame #15: 0x000000010dfe0baa citus.so`CreateDistributedPlannedStmt(planContext=0x00007ffee4886130) at distributed_planner.c:667:3
frame #16: 0x000000010dfdfbce citus.so`PlanDistributedStmt(planContext=0x00007ffee4886130, rangeTableList=0x000000010e2be330, rteIdCounter=) at distributed_planner.c:598:24
frame #17: 0x000000010dfdf6d8 citus.so`distributed_planner(parse=0x00007fefa10946c8, cursorOptions=, boundParams=) at distributed_planner.c:254:14
frame #18: 0x000000010b65bcb8 postgres`pg_plan_query(querytree=0x00007fefa10946c8, cursorOptions=256, boundParams=0x0000000000000000) at postgres.c:878:9
frame #19: 0x000000010b65bdce postgres`pg_plan_queries(querytrees=, cursorOptions=256, boundParams=0x0000000000000000) at postgres.c:968:11
frame #20: 0x000000010b65dafe postgres`exec_simple_query(query_string="SELECT MAX(CAST(0.800353 AS MONEY)), ('' COLLATE \"C\")\nFROM ONLY t0\nGROUP BY t0.c1\nHAVING (MAX(CAST(0.5828514 AS MONEY))) IS NOT NULL\nUNION ALL\nSELECT MAX((0.800353)::MONEY), ('')\nFROM ONLY t0\nGROUP BY t0.c1\nHAVING NOT ((MAX((0.5828514)::MONEY)) IS NOT NULL)\nUNION ALL\nSELECT ALL MAX(CAST(0.800353 AS MONEY)), ('')\nFROM ONLY t0\nGROUP BY t0.c1\nHAVING ((MAX((0.5828514)::MONEY)) IS NOT NULL) IS NULL;") at postgres.c:1143:19
frame #21: 0x000000010b65d395 postgres`PostgresMain(argc=, argv=, dbname=, username=) at postgres.c:0
frame #22: 0x000000010b5e7fc6 postgres`BackendRun(port=0x000000010b9a9a7a) at postmaster.c:4448:2
frame #23: 0x000000010b5e7889 postgres`BackendStartup(port=) at postmaster.c:4139:3
frame #24: 0x000000010b5e7065 postgres`ServerLoop at postmaster.c:1704:7
frame #25: 0x000000010b5e5117 postgres`PostmasterMain(argc=3, argv=0x00007fef9e403230) at postmaster.c:1377:11
frame #26: 0x000000010b54f1b6 postgres`main(argc=3, argv=0x00007fef9e403230) at main.c:228:3
frame #27: 0x00007fff596b63d5 libdyld.dylib`start + 1
frame #28: 0x00007fff596b63d5 libdyld.dylib`start + 1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.