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

A logic bug with distributed table #7783

Closed
duerwuyi opened this issue Dec 9, 2024 · 4 comments · Fixed by #7907
Closed

A logic bug with distributed table #7783

duerwuyi opened this issue Dec 9, 2024 · 4 comments · Fixed by #7907

Comments

@duerwuyi
Copy link

duerwuyi commented Dec 9, 2024

How to reproduce

Citus version: Citus 12.1.6 on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
init state:

DROP TABLE IF EXISTS t0;
create table t0 ( 
vkey int4 ,
pkey int4 ,
c0 timestamp ,
c1 numeric ,
c2 timestamp ,
c3 timestamp 

);
DROP TABLE IF EXISTS t1;
create table t1 ( 
vkey int4 ,
pkey int4 ,
c4 timestamp ,
c5 text ,
c6 int4 ,
c7 numeric ,
c8 int4 ,
c9 numeric ,
c10 int4 ,
c11 text 
);

SELECT create_reference_table('t1');
insert into t0 (vkey, pkey, c0, c1, c2, c3) values 
(7, 17000, make_timestamp(2070, 1, 18, 14, 45, 3), null::numeric, make_timestamp(1984, 8, 28, 3, 32, 23), make_timestamp(1970, 4, 13, 14, 30, 45));

query

delete from t0
where TRUE or
 (((t0.vkey) >= ( 
      select  
          pg_catalog.regexp_count(ref_0.c5, ref_0.c11)
        from 
          t1 as ref_0
        where true
          )));

result: 0 rows deleted

Excepted result:

the WHERE clause is : WHERE TRUE or ……, so the correct result should be: 1 rows deleted.

Comparison and EXPLAIN result:

when without citus, the query returns correctly: 1 rows deleted.

EXPLAIN result:

Custom Scan (Citus Adaptive)  (cost=0.00..0.00 rows=0 width=0)
  Task Count: 0
  Tasks Shown: All
@colm-mchugh
Copy link
Contributor

@duerwuyi thanks for bringing to our attention, (and #7783), I can confirm we can reproduce. It looks like an issue with Citus' expression processing. We will investigate further and fix.

@duerwuyi
Copy link
Author

duerwuyi commented Dec 16, 2024

@duerwuyi thanks for bringing to our attention, (and #7783), I can confirm we can reproduce. It looks like an issue with Citus' expression processing. We will investigate further and fix.

Thanks for your confirming. I wonder if #7696 #7697 #7698 can be reproduced in your computer, and they seem still exist with 12.1.6. Are they independent bugs caused by different logical defects?

@colm-mchugh
Copy link
Contributor

Thanks for your confirming. I wonder if #7696 #7697 #7698 can be reproduced in your computer, and they seem still exist with 12.1.6. Are they independent bugs caused by different logical defects?

We have reproduced #7696, #7697 and #7698, it looks like they may be symptoms of the same underlying problem (to be confirmed), and this looks unrelated to this issue (#7783), but we need to investigate further and confirm.

colm-mchugh added a commit that referenced this issue Jan 16, 2025
colm-mchugh added a commit that referenced this issue Feb 20, 2025
DESCRIPTION: fix a planning error caused by a redundant WHERE clause
(of the form WHERE true OR <expression>)

Fix a Citus planning glitch, where the WHERE clause of
the query is of the form:
` WHERE true OR <expression with 1 or more citus tables> `
and this is the only place in the query referencing a citus
table. Postgres' standard planner transforms the WHERE clause to:
` WHERE true `
So the query now has no citus tables, confusing the Citus planner
as described in issues #7782 and #7783. The fix is to check, after
Postgres standard planner, if the Query has been transformed as
shown, and re-run the check of whether or not the query needs
distributed planning.
colm-mchugh added a commit that referenced this issue Feb 21, 2025
DESCRIPTION: fix a planning error caused by a redundant WHERE clause
(of the form WHERE true OR <expression>)

Fix a Citus planning glitch, where the WHERE clause of
the query is of the form:
` WHERE true OR <expression with 1 or more citus tables> `
and this is the only place in the query referencing a citus
table. Postgres' standard planner transforms the WHERE clause to:
` WHERE true `
So the query now has no citus tables, confusing the Citus planner
as described in issues #7782 and #7783. The fix is to check, after
Postgres standard planner, if the Query has been transformed as
shown, and re-run the check of whether or not the query needs
distributed planning.
colm-mchugh added a commit that referenced this issue Feb 21, 2025
DESCRIPTION: fix a planning error caused by a redundant WHERE clause
(of the form WHERE true OR <expression>)

Fix a Citus planning glitch, where the WHERE clause of
the query is of the form:
` WHERE true OR <expression with 1 or more citus tables> `
and this is the only place in the query referencing a citus
table. Postgres' standard planner transforms the WHERE clause to:
` WHERE true `
So the query now has no citus tables, confusing the Citus planner
as described in issues #7782 and #7783. The fix is to check, after
Postgres standard planner, if the Query has been transformed as
shown, and re-run the check of whether or not the query needs
distributed planning.
colm-mchugh added a commit that referenced this issue Feb 24, 2025
DESCRIPTION: fix a planning error caused by a redundant WHERE clause
(of the form WHERE true OR <expression>)

Fix a Citus planning glitch, where the WHERE clause of
the query is of the form:
` WHERE true OR <expression with 1 or more citus tables> `
and this is the only place in the query referencing a citus
table. Postgres' standard planner transforms the WHERE clause to:
` WHERE true `
So the query now has no citus tables, confusing the Citus planner
as described in issues #7782 and #7783. The fix is to check, after
Postgres standard planner, if the Query has been transformed as
shown, and re-run the check of whether or not the query needs
distributed planning.
colm-mchugh added a commit that referenced this issue Feb 26, 2025
DESCRIPTION: fix a planning error caused by a redundant WHERE clause
(of the form WHERE true OR <expression>)

Fix a Citus planning glitch, where the WHERE clause of
the query is of the form:
` WHERE true OR <expression with 1 or more citus tables> `
and this is the only place in the query referencing a citus
table. Postgres' standard planner transforms the WHERE clause to:
` WHERE true `
So the query now has no citus tables, confusing the Citus planner
as described in issues #7782 and #7783. The fix is to check, after
Postgres standard planner, if the Query has been transformed as
shown, and re-run the check of whether or not the query needs
distributed planning.
colm-mchugh added a commit that referenced this issue Feb 27, 2025
DESCRIPTION: fix a planning error caused by a redundant WHERE clause

Fix a Citus planning glitch that occurs in a DML query when the WHERE
clause of the query is of the form:
    ` WHERE true OR <expression with 1 or more citus tables> `
and this is the only place in the query referencing a citus table.
Postgres' standard planner transforms the WHERE clause to:
    ` WHERE true `
So the query now has no citus tables, confusing the Citus planner as
described in issues #7782 and #7783. The fix is to check, after Postgres
standard planner, if the Query has been transformed as shown, and re-run
the check of whether or not the query needs distributed planning.
@colm-mchugh
Copy link
Contributor

Fixed by #7907

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

Successfully merging a pull request may close this issue.

2 participants