Hello,

I looked into the rule recently but to be honest I already forgot what it
really does.

Expect: B
Hope: A
Comments:
Judging by the name I would expect B, pushing as much as possible from the
top project but not altering the filter.
In the end it is just a transpose.

On the other hand, I would use the rule mostly as an alternative to
RelFieldTrimmer (along with other rules) in order
to prune out unnecessary columns as early as possible. Thus, I think option
A is what I would like.

If it works like B then in some cases it could have also the opposite
effect of what I would like; fattening the tuples
instead of slimming them down.

SELECT sal, comm, sal + comm AS remuneration, sal * 0.45 AS incometax, sal
* 0.03 AS surchargetax
FROM Emp
WHERE deptno = 10

SELECT sal, comm, renumeration, incometax, surchargetax
FROM (
  SELECT sal, comm, sal + comm AS remuneration, sal * 0.45 As incometax,
sal * 0.03 AS surchargetax, deptno
  FROM Emp)
WHERE deptno = 10

Best,
Stamatis

PS. I will go now and check what the rule does :)


On Wed, May 27, 2020 at 8:45 PM Julian Hyde <jh...@apache.org> wrote:

> As part of https://issues.apache.org/jira/browse/CALCITE-3975, I've
> been looking into what ProjectFilterTransposeRule does with
> expressions. It's one of our oldest rules, and I thought I knew what
> it did. But the rule does not do what I expect. I've like to conduct a
> straw poll to see what other people think.
>
> Consider the following query (a Project on top of a Filter on a Scan).
>
>   SELECT sal + comm AS remuneration
>   FROM Emp
>   WHERE deptno = 10
>
> After applying ProjectFilterTransposeRule, what result would you
> expect? What would the ideal result be? Are there any extreme cases
> (large project lists, complex expressions, expensive filter
> expressions) where the rule should do something different?
>
> Please fill out the following:
>
>   Expect: <option A, B or C, or a query>
>   Hope: <option A, B or C, or a query>
>   Comments:
>
> Option A. Push down references to the fields needed by filter and
> project expressions
>
>   SELECT sal + comm AS remuneration
>   FROM (
>     SELECT sal, comm, deptno
>     FROM Emp)
>   WHERE deptno = 10
>
> B. Push down the project expression, and references to the fields
> needed by the filter
>
>   SELECT remuneration
>   FROM (
>     SELECT sal + comm  AS remuneration, deptno
>     FROM Emp)
>   WHERE deptno = 10
>
> C. Push down the project and filter expressions
>
>  SELECT remuneration
>   FROM (
>     SELECT sal + comm  AS remuneration, deptno = 10 AS predicate
>     FROM Emp)
>   WHERE predicate
>
> Julian
>

Reply via email to