GnuCash Daily Source Diff

Dave Peticolas dave@krondo.com
07 Nov 2001 13:51:44 -0800


--=-Q3wB5Wr701B1rQDfaGlT
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Wed, 2001-11-07 at 07:49, Linas Vepstas wrote:
> Hi Dave,
>=20
> On Wed, Nov 07, 2001 at 08:04:31AM -0600, Dave Peticolas was heard to rem=
ark:
> > -      sq->pq =3D stpcpy(sq->pq, ", gncCommodity");
> > +      sq->pq =3D stpcpy(sq->pq, ", gncCommodity account_com");
>=20
> Hell of a trick.  I assume its purpose is a performance hack?

That is actually a bug fix. If a query happened to contain
both a split amount predicate and a split value predicate,
you would get something like:

... AND gncCommodity.commodity=3DgncTransaction.currency ...
... AND gncCommodity.commodity=3DgncAccount.commodity ...

Thus, the query would succeed only if the transaction had
the same commodity as the account, since the gncCommodity
reference had to refer to the same row. To disambiguate
them, you need a 'self-join' where you refer to two or
more separate instances of the same table, like this:

... AND account_com.commodity=3DgncTransaction.currency ...
... AND trans_com.commodity=3DgncAccount.commodity ...


> Where did you learn this???

I learned it from the book "Postgresql: Introduction and Concepts"
by Bruce Momjian, who is one of the main Postgres people. Pretty
good book, I thought.

dave


--=-Q3wB5Wr701B1rQDfaGlT
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQA76azw5effKKCmfpIRAsU7AKCAIOyH8BZU9RROQ/b8eYMn66/VRwCbBVaI
i/kch9eLMzfA/vAMotuoxwU=
=dBkh
-----END PGP SIGNATURE-----

--=-Q3wB5Wr701B1rQDfaGlT--