[Jifty-commit] jifty-dbi branch, master, updated. 2fc4311e7293be1075194dbcbd2b6e0c97b01cce

Jifty commits jifty-commit at lists.jifty.org
Thu Dec 31 14:44:44 EST 2009


The branch, master has been updated
       via  2fc4311e7293be1075194dbcbd2b6e0c97b01cce (commit)
       via  5bc754ca2e306efe22a8fd7bc89206ebb96844fd (commit)
      from  91b7ff2f08416fc64d6b6dfae5eeb0c2dd8ce00a (commit)

Summary of changes:
 lib/Jifty/DBI/Collection.pm |    2 +-
 lib/Jifty/DBI/Column.pm     |   21 ++++++++++++++-------
 lib/Jifty/DBI/Record.pm     |    9 +++++++--
 3 files changed, 22 insertions(+), 10 deletions(-)

- Log -----------------------------------------------------------------
commit 5bc754ca2e306efe22a8fd7bc89206ebb96844fd
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Dec 31 14:25:17 2009 -0500

    When generating COUNT, don't add a DISTINCT unless we need it
    
    A simple check of ->distinct_required is not sufficient -- when
    building joins for prefetch, we explicitly mark them as "distinct"
    joins, because we want all of their table's rows back for every one of
    the primary row.  When doing a count, however, we either need to
    un-join the prefetch tables, or simply elect to add a DISTINCT.
    
    Since this is still strictly better than previously, in the common
    case of actual distinct joins, this corner case is acceptable, and
    indeed no worse than it was previously.

diff --git a/lib/Jifty/DBI/Collection.pm b/lib/Jifty/DBI/Collection.pm
index 44e80ef..7e53184 100755
--- a/lib/Jifty/DBI/Collection.pm
+++ b/lib/Jifty/DBI/Collection.pm
@@ -802,7 +802,7 @@ sub build_select_count_query {
     }
 
     # DISTINCT query only required for multi-table selects
-    if ( $self->_is_joined ) {
+    if ( $self->distinct_required or $self->prefetch_related ) {
         $query_string = $self->_handle->distinct_count( \$query_string );
     } else {
         $query_string = "SELECT count(main.id) FROM " . $query_string;

commit 2fc4311e7293be1075194dbcbd2b6e0c97b01cce
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Dec 31 14:38:00 2009 -0500

    Add an attribute which controls placeholder use for load_by_cols
    
    Postgres allows for partial indexes, but can only use them if the
    values are known at prepare time, when the query plan is generated.
    The no_placeholder attribute tells load_by_cols to insert the value
    into the statement directly (quoted, of course), instead of at
    execute-time, using a placeholder.  This allows Postgres to make use
    of partial indexes on the given column.

diff --git a/lib/Jifty/DBI/Column.pm b/lib/Jifty/DBI/Column.pm
index d12ac21..014f183 100644
--- a/lib/Jifty/DBI/Column.pm
+++ b/lib/Jifty/DBI/Column.pm
@@ -42,6 +42,7 @@ my @handy_attrs = qw/
     valid_values
     available_values
     autocompleted
+    no_placeholder
     /;
 
 # compat: this should probably never exist and be deprecated
@@ -138,19 +139,25 @@ known attributes are:
 
 =over
 
-=item     container
+=item container
 
-=item     label hints render_as
+=item label hints render_as
 
-=item     display_length
+=item display_length
 
-=item     valid_values
+=item valid_values
 
-=item     available_values
+=item available_values
 
-=item     autocompleted
+=item autocompleted
 
-=item     documentation
+=item documentation
+
+=item no_placeholder
+
+Setting this to a true value causes L<Jifty::DBI::record/load_by_cols>
+to not use a placeholder when loading the column.  This can allow the
+database to come up with better query plans in some cases.
 
 =back
 
diff --git a/lib/Jifty/DBI/Record.pm b/lib/Jifty/DBI/Record.pm
index fcde122..6fc24cd 100755
--- a/lib/Jifty/DBI/Record.pm
+++ b/lib/Jifty/DBI/Record.pm
@@ -1140,8 +1140,13 @@ sub load_by_cols {
                 }
             }
 
-            push @phrases, "$key $op $function";
-            push @bind,    $value;
+            if ($column_obj and $column_obj->no_placeholder and $function eq "?") {
+                push @phrases, "$key $op ".$self->_handle->quote_value($value);
+            } else {
+                push @phrases, "$key $op $function";
+                push @bind,    $value;
+            }
+
         } elsif ( !defined $hash{$key} ) {
             push @phrases, "$key IS NULL";
         } else {

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


More information about the Jifty-commit mailing list