From: Craig A. James <cjames@modgraph-usa.com>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: pgsql-performance@postgresql.org
Subject: Re: [HACKERS] EXISTS optimization
Date: Tue, 03 Apr 2007 14:47:30 -0700
Message-ID: <4612CB72.6010804@modgraph-usa.com> (raw)
In-Reply-To: <46044683.EE98.0025.0@wicourts.gov>
References: <4603C1A3.EE98.0025.0@wicourts.gov>
<25339.1174686582@sss.pgh.pa.us>
<46040DAC.EE98.0025.0@wicourts.gov>
<b6e8f2e80703231604v72b9dc4dr51eebd62274d53ec@mail.gmail.com>
<46044683.EE98.0025.0@wicourts.gov>
Kevin Grittner wrote:
> Management has simply given a mandate that the software be independent
> of OS and database vendor, and to use Java to help with the OS independence.
> ... we write all of our queries in ANSI SQL in our own query tool, parse it,
> and generate Java classes to run it.
A better solution, and one I've used for years, is to use OS- or database-specific features, but carefully encapsulate them in a single module, for example, "database_specific.java".
For example, when I started supporting both Oracle and Postgres, I encountered the MAX() problem, which (at the time) was very slow in Postgres, but could be replaced by "select X from MYTABLE order by X desc limit 1". So I created a function, "GetColumnMax()" that encapsulates the database-specific code for this. Similar functions encapsulate and a number of other database-specific optimizations.
Another excellent example: I have a function called "TableExists(name)". To the best of my knowledge, there simply is no ANSI SQL for this, so what do you do? Encapsulate it in one place.
The result? When I port to a new system, I know exactly where to find all of the non-ANSI SQL. I started this habit years ago with C/C++ code, which has the same problem: System calls are not consistent across the varients of Unix, Windows, and other OS's. So you put them all in one file called "machine_dependent.c".
Remember the old adage: There is no such thing as portable code, only code that has been ported.
Cheers,
Craig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: cjames@modgraph-usa.com, Kevin.Grittner@wicourts.gov
Subject: Re: [HACKERS] EXISTS optimization
In-Reply-To: <4612CB72.6010804@modgraph-usa.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox