Hope this is the last one,

    Bruce, please apply.

    The patch does 2 things:

        Fixes  a  bug  in  the rule system that caused a crashing
        backend when a join-view with calculated column  is  used
        in subselect.

        Modifies  EXPLAIN to explain rewritten queries instead of
        the plain SeqScan on a view. Rules can produce very  deep
        nested plans, so I lowered the indentation a little.

    The  patch  is regression tested. Now the rule system handles
    this:

        DELETE FROM shoelace WHERE EXISTS
            (SELECT * FROM shoelace_candelete
                     WHERE sl_name = shoelace.sl_name);

    Doesn't look that complicated. But:

    View shoelace is a join of 2 tables with a calculated column.

    View   shoelace_candelete   is   a   qualified   select  from
    shoelace_obsolete.

    View shoelace_obsolete is  a  select  from  shoelace  with  a
    subselect  qualification  from  shoe.  The  subselect  has  a
    qualification that compares calculated columns from shoe  and
    shoelace.

    View shoe is a join of 2 tables with 2 calculated columns.


    AND IT WORKS! The generated plan is:

    Nested Loop
      ->  Merge Join
            ->  Seq Scan
                  ->  Sort
                        ->  Seq Scan on shoelace_data
            ->  Seq Scan
                  ->  Sort
                        ->  Seq Scan on shoelace_data s
                              SubPlan
                                ->  Merge Join
                                      ->  Seq Scan
                                            ->  Sort
                                                  ->  Seq Scan on shoelace_data s
                                      ->  Seq Scan
                                            ->  Sort
                                                  ->  Seq Scan on unit u
                                      SubPlan
                                        ->  Merge Join
                                              ->  Seq Scan
                                                    ->  Sort
                                                          ->  Seq Scan on shoe_data sh
                                              ->  Seq Scan
                                                    ->  Sort
                                                          ->  Seq Scan on unit un
      ->  Seq Scan on unit u




    What a plan. 6 scans over nested  subselects for one  DELETE.
    I think that is close to the rule system we wanted.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#======================================== jwieck@debis.com (Jan Wieck) #


begin 644 rule_fix.diff.gz
M'XL("(7)+38"`W)U;&5?9FEX+F1I9F8`Y1UK<]LV\K/Z*Z#<M-6#BMZ.93>>
MR:69.]^D2>LX;;]I:`J2>:%)'4G9]67\WV\7`$&0!$2*EIQD+M/*(@GL&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NXZ3H?7;/O3I\23MTW385K,W]82--0\EJJOJW.NW&#7;/R",WOKZML
MV#LA4'?25<$@7/PF24]5%](1B+.;YIJJ;+9MFJM.=G'/W-XEH^Z..PSPS#ZX
MRA/*3BBR.]X>/6EEW>]*Q:OYL_4TQ:O-1Q>O)A7=J:N?^26-;#0H?DBC7SGI
MOL.Q'U^M2YYCL9I+GNZ,;!9W1GX)/[V4"[V?OB<^#N:\E[*E==X/PE4]C[Z4
M`9U'?Q#KJNGFES)@=/,/,T8>[?N7,E3B^]=A:T?,AH#@"3`_/49=Z'`0RSE0
M/*'N'C*?]M'<?MI'L_2T#_*M11TF`]@:=105K]/\$\4BU6<,4RQ2;_CLA%47
MH.R,UARUD/U$+:6\F*.6P\I0%\H\`49M?/,$>/5!SWZGVQJ14/X@PJ>(A)++
M75]]%"O)Q4^@ZDNWKUEU]_8FV4KR[6V+E>33HVPE^6[]QR>C+;]),CRV1O(L
M>?E;K\],O_7Z+#EN/OGQRZ2:GKTJ0S$7HG-#7?FI4$OMJB^Q`X#H7T-Q4BHI
<G/^`!A=$_N=T#R\(RTS_UR":_P%H_<@64GD`````
`
end


Wed, 21 Oct 1998 14:18:50 +0200 (MET DST)
jwieck@debis.com (Jan Wieck)
One more bugfix
Applied.


> Hope this is the last one,
> 
>     Bruce, please apply.
> 
>     The patch does 2 things:
> 
>         Fixes  a  bug  in  the rule system that caused a crashing
>         backend when a join-view with calculated column  is  used
>         in subselect.
> 
>         Modifies  EXPLAIN to explain rewritten queries instead of
>         the plain SeqScan on a view. Rules can produce very  deep
>         nested plans, so I lowered the indentation a little.
> 
>     The  patch  is regression tested. Now the rule system handles
>     this:
> 
>         DELETE FROM shoelace WHERE EXISTS
>             (SELECT * FROM shoelace_candelete
>                      WHERE sl_name = shoelace.sl_name);
> 
>     Doesn't look that complicated. But:
> 
>     View shoelace is a join of 2 tables with a calculated column.
> 
>     View   shoelace_candelete   is   a   qualified   select  from
>     shoelace_obsolete.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Wed, 21 Oct 1998 12:21:16 -0400 (EDT)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] One more bugfix