Re: Patch to make SelectQueries work...

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sun Apr 17 2005 - 09:58:35 EDT

  • Next message: Mikaël Cluseau: "Re: Patch to make SelectQueries work..."

    Mikaël,

    I applied the patch - thanks!

    Re: subselects. You are talking about queries with qualifiers over
    to-many relationships, right? As this is the case when DISTINCT is
    added behind the scenes. I've done some research in this area before -
    http://www.objectstyle.org/cayenne/lists/cayenne-user/2003/05/0031.html
      I've been thinking of adding this as an alternative translation
    strategy configurable either per query or per adapter.

    Can't say when. Patches are always welcome ;-)

    However I just realized that Cayenne already supports another strategy
    described above - fetching duplicate rows and then internally applying
    "distinct" logic, returning rows with unique PK. Can't say if this is
    faster than PostgeSQL distinct ... somebody needs to try. The actual
    worker class is
    "org.objectstyle.cayenne.access.util.DistinctResultIterator". It is
    used behind the scenes if SelectTranslator returns true from
    "isSuppressingDistinct" method.

    Setting this up is not very user-friendly right now, as it wasn't
    intended for public use, but if we have proof that it actually improves
    performance, we can make it one of SelectQuery flags.

    Andrus

    On Apr 15, 2005, at 4:32 PM, Mikaël Cluseau wrote:
    > ... with custom DB attributes in queries with multiple tables.
    >
    > Thanks for the good work, really.
    >
    > As I'm there, is there a way to have subselect queries in Cayenne? Is
    > it
    > planned? I ask because in PostgreSQL (at least 7.4 series), a SELECT
    > DISTINCT trigger a sort on every wanted field... (in fact, the primary
    > key is sufficient since it holds the functionnal dependency). The
    > solution is a subquery :
    >
    > SELECT t0.* FROM my_table t0 WHERE t0.pk IN (SELECT DISTINCT t0.pk FROM
    > my_table t0, my_table t1 WHERE ...)
    >
    > On my system, this query runs in 0.3 seconds, while the simple :
    >
    > SELECT DISTINCT t0.* FROM my_table t0, my_table t1 WHERE ...
    >
    > takes 26 seconds (in case anyone had performance problems with
    > PostgreSQL), although it is simpler and strictly equivalent.
    >
    > --------- the patch --------
    >
    > Index: SelectTranslator.java
    > ===================================================================
    > RCS file:
    > /cvsroot/cayenne/cayenne/src/cayenne/java/org/objectstyle/cayenne/
    > access/trans/SelectTranslator.java,v
    > retrieving revision 1.40
    > diff -u -r1.40 SelectTranslator.java
    > --- SelectTranslator.java 19 Mar 2005 19:49:22 -0000 1.40
    > +++ SelectTranslator.java 15 Apr 2005 20:12:19 -0000
    >.. -570,7 +570,8 @@
    > + customAttributes.get(i));
    > }
    >
    > - columns.add(new ColumnDescriptor(attribute, null));
    > + String alias = aliasForTable((DbEntity)
    > attribute.getEntity());
    > + columns.add(new ColumnDescriptor(attribute, alias));
    > }
    >
    > return columns;
    >
    >



    This archive was generated by hypermail 2.0.0 : Sun Apr 17 2005 - 09:58:40 EDT