Implement predicate propagation for non-equivalence clauses

2018-09-04 Thread Richard Guo
idth=4) -> Seq Scan on b (cost=0.00..170.00 rows=9990 width=4) Filter: (i > 10) (7 rows) In general, if the selectivity of the implied qual is low, the extra cost for relation scan is more likely to be compromised by the cost reduced in join, and vise versa. Thanks Richa

Implement predicate propagation for non-equivalence clauses

2018-09-04 Thread Richard Guo
idth=4) -> Seq Scan on b (cost=0.00..170.00 rows=9990 width=4) Filter: (i > 10) (7 rows) In general, if the selectivity of the implied qual is low, the extra cost for relation scan is more likely to be compromised by the cost reduced in join, and vise versa. Thanks Richa

Re: Implement predicate propagation for non-equivalence clauses

2019-02-03 Thread Andres Freund
Hi, On 2018-11-22 19:15:42 +0300, Alexander Kuzmenkov wrote: > Hi Richard, > > I took a look at the v2, here are some comments: > > * This feature needs tests, especially for the cases where opfamilies or > data types or collations don't match, and other non-obvious cases where it > shouldn't wo

Re: Implement predicate propagation for non-equivalence clauses

2018-11-22 Thread Alexander Kuzmenkov
Hi Richard, I took a look at the v2, here are some comments: * This feature needs tests, especially for the cases where opfamilies or data types or collations don't match, and other non-obvious cases where it shouldn't work. * Deducing an inequality to a constant is not always helpful. If w

Re: Implement predicate propagation for non-equivalence clauses

2018-09-26 Thread Richard Guo
Hi, Thanks everyone for reviewing. We updated the patch and added more strict checks for the non-equivalence clauses before deducing new quals, including: 1) The non-equivalence clause for deduction can only be type of OpExpr or ScalarArrayOpExpr, with two arguments. 2) The operator of the non-e

Re: Implement predicate propagation for non-equivalence clauses

2018-09-04 Thread Heikki Linnakangas
On 05/09/18 09:34, Richard Guo wrote: Hi, As we know, current planner will generate additional restriction clauses from equivalence clauses. This will generally lower the total cost because some of tuples may be filtered out before joins. In this patch, we are trying to do the similar deduct

Re: Implement predicate propagation for non-equivalence clauses

2018-09-04 Thread Tom Lane
Richard Guo writes: > In this patch, we are trying to do the similar deduction, from > non-equivalence > clauses, that is, A=B AND f(A) implies A=B AND f(A) and f(B), under some > restrictions on f. Uh, *what* restrictions on f()? In general the above equivalence does not hold, at least not for

Re: Implement predicate propagation for non-equivalence clauses

2018-09-05 Thread Richard Guo
On Wed, Sep 5, 2018 at 2:55 PM, Heikki Linnakangas wrote: > On 05/09/18 09:34, Richard Guo wrote: > >> Hi, >> >> As we know, current planner will generate additional restriction clauses >> from >> equivalence clauses. This will generally lower the total cost because >> some of >> tuples may be fi

Re: Implement predicate propagation for non-equivalence clauses

2018-09-05 Thread Richard Guo
Hi, On Wed, Sep 5, 2018 at 2:56 PM, Tom Lane wrote: > Richard Guo writes: > > In this patch, we are trying to do the similar deduction, from > > non-equivalence > > clauses, that is, A=B AND f(A) implies A=B AND f(A) and f(B), under some > > restrictions on f. > > Uh, *what* restrictions on f()

Re: Implement predicate propagation for non-equivalence clauses

2019-02-03 Thread Andres Freund
Hi, On 2018-11-22 19:15:42 +0300, Alexander Kuzmenkov wrote: > Hi Richard, > > I took a look at the v2, here are some comments: > > * This feature needs tests, especially for the cases where opfamilies or > data types or collations don't match, and other non-obvious cases where it > shouldn't wo

Re: Implement predicate propagation for non-equivalence clauses

2018-11-22 Thread Alexander Kuzmenkov
Hi Richard, I took a look at the v2, here are some comments: * This feature needs tests, especially for the cases where opfamilies or data types or collations don't match, and other non-obvious cases where it shouldn't work. * Deducing an inequality to a constant is not always helpful. If w

Re: Implement predicate propagation for non-equivalence clauses

2018-09-04 Thread Heikki Linnakangas
On 05/09/18 09:34, Richard Guo wrote: Hi, As we know, current planner will generate additional restriction clauses from equivalence clauses. This will generally lower the total cost because some of tuples may be filtered out before joins. In this patch, we are trying to do the similar deduct

Re: Implement predicate propagation for non-equivalence clauses

2018-09-04 Thread Tom Lane
Richard Guo writes: > In this patch, we are trying to do the similar deduction, from > non-equivalence > clauses, that is, A=B AND f(A) implies A=B AND f(A) and f(B), under some > restrictions on f. Uh, *what* restrictions on f()? In general the above equivalence does not hold, at least not for

Re: Implement predicate propagation for non-equivalence clauses

2018-09-05 Thread Richard Guo
On Wed, Sep 5, 2018 at 2:55 PM, Heikki Linnakangas wrote: > On 05/09/18 09:34, Richard Guo wrote: > >> Hi, >> >> As we know, current planner will generate additional restriction clauses >> from >> equivalence clauses. This will generally lower the total cost because >> some of >> tuples may be fi

Re: Implement predicate propagation for non-equivalence clauses

2018-09-05 Thread Richard Guo
Hi, On Wed, Sep 5, 2018 at 2:56 PM, Tom Lane wrote: > Richard Guo writes: > > In this patch, we are trying to do the similar deduction, from > > non-equivalence > > clauses, that is, A=B AND f(A) implies A=B AND f(A) and f(B), under some > > restrictions on f. > > Uh, *what* restrictions on f()

Re: Implement predicate propagation for non-equivalence clauses

2018-09-26 Thread Richard Guo
Hi, Thanks everyone for reviewing. We updated the patch and added more strict checks for the non-equivalence clauses before deducing new quals, including: 1) The non-equivalence clause for deduction can only be type of OpExpr or ScalarArrayOpExpr, with two arguments. 2) The operator of the non-e