[freeside-commits] branch FREESIDE_4_BRANCH updated. c7f2b1fd6325796123e2df32b3e27ff7ec466024

Christopher Burger burgerc at freeside.biz
Thu Jun 14 12:09:51 PDT 2018


The branch, FREESIDE_4_BRANCH has been updated
       via  c7f2b1fd6325796123e2df32b3e27ff7ec466024 (commit)
      from  59ddd641e1242710868f20c51d0d4249098bcc0a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c7f2b1fd6325796123e2df32b3e27ff7ec466024
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Jan 31 19:17:13 2017 -0800

    further optimize condition_sql for "Invoice eligible for automatic collection" condition, RT#74451

diff --git a/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm b/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm
index 027625569..d782c12c1 100644
--- a/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm
+++ b/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm
@@ -26,32 +26,18 @@ sub condition {
 sub condition_sql {
   my( $class, $table, %opt ) = @_;
   
-  # XXX: can be made faster with optimizations?
-  # -remove some/all sub-selects?
-  # -remove the two main separate selects?
-
-  "0 = (select count(1) from cust_pkg 
-            where cust_pkg.no_auto = 'Y' and cust_pkg.pkgnum in
-                (select distinct cust_bill_pkg.pkgnum 
-                    from cust_bill_pkg, cust_pkg 
-                    where cust_bill_pkg.pkgnum = cust_pkg.pkgnum
-                        and cust_bill_pkg.invnum = cust_bill.invnum
-                        and cust_bill_pkg.pkgnum > 0
-                )
-        )
-   AND
-   0 = (select count(1) from part_pkg 
-            where part_pkg.no_auto = 'Y' and part_pkg.pkgpart in
-                (select cust_pkg.pkgpart from cust_pkg 
-                    where pkgnum in 
-                        (select distinct cust_bill_pkg.pkgnum 
-                            from cust_bill_pkg, cust_pkg 
-                            where cust_bill_pkg.pkgnum = cust_pkg.pkgnum 
-                                and cust_bill_pkg.invnum = cust_bill.invnum
-                                and cust_bill_pkg.pkgnum > 0
-                        ) 
-                )
-        )
+  # can be made still faster with optimizations?
+
+  "NOT EXISTS ( SELECT 1 FROM cust_pkg 
+                           LEFT JOIN part_pkg USING (pkgpart)
+                  WHERE ( cust_pkg.no_auto = 'Y' OR part_pkg.no_auto = 'Y' )
+                    AND cust_pkg.pkgnum IN
+                          ( SELECT DISTINCT cust_bill_pkg.pkgnum 
+                              FROM cust_bill_pkg
+                              WHERE cust_bill_pkg.invnum = cust_bill.invnum
+                                AND cust_bill_pkg.pkgnum > 0
+                          )
+              )
   ";
 }
 

-----------------------------------------------------------------------

Summary of changes:
 .../part_event/Condition/cust_bill_hasnt_noauto.pm | 38 +++++++---------------
 1 file changed, 12 insertions(+), 26 deletions(-)




More information about the freeside-commits mailing list