citusdata / citusdata/citus

Citus unnecessarily errors out for some expressions on WHERE clause

Open
#3,981 0 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

Found by SQLancer

```SQL

CREATE TABLE IF NOT EXISTS t0(c0 CHAR(47) );

-- same query works on Postgres
SELECT ALL t0.c0 FROM ONLY t0 WHERE (t0.c0) BETWEEN SYMMETRIC (t0.c0) AND (rtrim(CAST(0.97303731569614282381763814555597491562366485595703125 AS VARCHAR)));
c0
----
(0 rows)

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

-- fails on Citus
SELECT ALL t0.c0 FROM ONLY t0 WHERE (t0.c0) BETWEEN SYMMETRIC (t0.c0) AND (rtrim(CAST(0.97303731569614282381763814555597491562366485595703125 AS VARCHAR)));
ERROR: value too long for type character(47)
```

backtrace:
```
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x0000000102eba467 postgres`errstart(elevel=20, filename="varchar.c", lineno=312, funcname="bpchar", domain=0x0000000000000000) at elog.c:263:14
frame #1: 0x0000000102f92556 postgres`bpchar.cold.1 + 38
frame #2: 0x0000000102e974f5 postgres`bpchar(fcinfo=0x00007fb168941334) at varchar.c:309:6
frame #3: 0x0000000102c742c1 postgres`ExecInterpExpr(state=0x00007fb169843530, econtext=0x00007fb169843ad0, isnull=0x00007ffeed10ea66) at execExprInterp.c:649:8
frame #4: 0x0000000102d33a2d postgres`ExecEvalExprSwitchContext(state=0x00007fb169843530, econtext=0x00007fb169843ad0, isNull=) at executor.h:307:13
frame #5: 0x0000000102d3395c postgres`evaluate_expr(expr=, result_type=1042, result_typmod=51, result_collation=0) at clauses.c:4812:14
frame #6: 0x0000000102d341cd postgres`simplify_function(funcid=668, result_type=1042, result_typmod=1754548680, result_collid=0, input_collid=0, args_p=, funcvariadic=, process_args=, allow_non_const=, context=0x00007ffeed10ec28) at clauses.c:3984:12
frame #7: 0x0000000102d32a28 postgres`eval_const_expressions_mutator(node=0x00007fb1689448f0, context=0x00007ffeed10ec28) at clauses.c:2477:14
frame #8: 0x0000000102d320ca postgres`eval_const_expressions(root=, node=) at clauses.c:2269:9
frame #9: 0x0000000102d1ef40 postgres`expression_planner(expr=) at planner.c:6053:11
frame #10: 0x0000000105782df4 citus.so`TransformPartitionRestrictionValue(partitionColumn=0x00007fb168940ce0, restrictionValue=0x00007fb168941388, missingOk=) at shard_pruning.c:1254:31
frame #11: 0x00000001057835f6 citus.so`AddPartitionKeyRestrictionToInstance(context=0x00007ffeed10edb0, opClause=0x00007fb168941408, partitionColumn=0x00007fb168940ce0, constantClause=0x00007fb168941388) at shard_pruning.c:1114:20
frame #12: 0x0000000105783374 citus.so`PrunableExpressionsWalker(node=0x00007fb168944220, context=0x00007ffeed10edb0) at shard_pruning.c:833:6
frame #13: 0x0000000105782b70 citus.so`PrunableExpressions(tree=, context=0x00007ffeed10edb0) at shard_pruning.c:742:3
frame #14: 0x000000010578254f citus.so`PruneShards(relationId=74961, rangeTableId=1, whereClauseList=0x00007fb168944010, partitionValueConst=0x00007ffeed10eeb0) at shard_pruning.c:395:2
frame #15: 0x000000010577c7b9 citus.so`TargetShardIntervalsForRestrictInfo(restrictionContext=, multiShardQuery=0x00007ffeed10ef47, partitionValueConst=0x00007ffeed10efc0) at multi_router_planner.c:2514:30
frame #16: 0x000000010577c348 citus.so`PlanRouterQuery(originalQuery=0x00007fb1680017e0, plannerRestrictionContext=0x00007fb1689403d0, placementList=0x00007ffeed10efa8, anchorShardId=0x00007ffeed10efa0, relationShardList=0x00007ffeed10efb0, prunedShardIntervalListList=0x00007ffeed10efb8, replacePrunedQueryWithDummy=, multiShardModifyQuery=0x00007ffeed10efcf, partitionValueConst=0x00007ffeed10efc0) at multi_router_planner.c:2075:4
frame #17: 0x000000010577ac2b citus.so`RouterJob(originalQuery=0x00007fb1680017e0, plannerRestrictionContext=0x00007fb1689403d0, planningError=0x00007fb168943ef8) at multi_router_planner.c:1650:22
frame #18: 0x000000010577a68a citus.so`CreateSingleTaskRouterSelectPlan(distributedPlan=0x00007fb168943e70, originalQuery=0x00007fb1680017e0, query=, plannerRestrictionContext=0x00007fb1689403d0) at multi_router_planner.c:268:13
frame #19: 0x000000010577a3ff citus.so`CreateRouterPlan(originalQuery=0x00007fb1680017e0, query=0x00007fb1680018f8, plannerRestrictionContext=0x00007fb1689403d0) at multi_router_planner.c:187:3
frame #20: 0x000000010576494b citus.so`CreateDistributedPlan(planId=25, originalQuery=0x00007fb1680017e0, query=0x00007fb1680018f8, boundParams=0x0000000000000000, hasUnresolvedParams=, plannerRestrictionContext=0x00007fb1689403d0) at distributed_planner.c:963:21
frame #21: 0x0000000105765a7a citus.so`CreateDistributedPlannedStmt(planContext=0x00007ffeed10f138) at distributed_planner.c:678:3
frame #22: 0x000000010576461e citus.so`PlanDistributedStmt(planContext=0x00007ffeed10f138, rteIdCounter=) at distributed_planner.c:609:24
frame #23: 0x00000001057642e3 citus.so`distributed_planner(parse=0x00007fb1680018f8, cursorOptions=, boundParams=) at distributed_planner.c:225:14
frame #24: 0x0000000102dd2cb8 postgres`pg_plan_query(querytree=0x00007fb1680018f8, cursorOptions=256, boundParams=0x0000000000000000) at postgres.c:878:9
frame #25: 0x0000000102dd2dce postgres`pg_plan_queries(querytrees=, cursorOptions=256, boundParams=0x0000000000000000) at postgres.c:968:11
frame #26: 0x0000000102dd4afe postgres`exec_simple_query(query_string="SELECT ALL t0.c0 FROM ONLY t0 WHERE (t0.c0) BETWEEN SYMMETRIC (t0.c0) AND (rtrim(CAST(0.9730373156961428238176381455559749156236648550 AS VARCHAR)));") at postgres.c:1143:19
frame #27: 0x0000000102dd4395 postgres`PostgresMain(argc=, argv=, dbname=, username=) at postgres.c:0
frame #28: 0x0000000102d5efc6 postgres`BackendRun(port=0x0000000103120a7a) at postmaster.c:4448:2
frame #29: 0x0000000102d5e889 postgres`BackendStartup(port=) at postmaster.c:4139:3
frame #30: 0x0000000102d5e065 postgres`ServerLoop at postmaster.c:1704:7
frame #31: 0x0000000102d5c117 postgres`PostmasterMain(argc=3, argv=0x00007fb166700780) at postmaster.c:1377:11
frame #32: 0x0000000102cc61b6 postgres`main(argc=3, argv=0x00007fb166700780) at main.c:228:3
frame #33: 0x00007fff596b63d5 libdyld.dylib`start + 1
frame #34: 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.