Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] EXISTS optimization

From: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>
To: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: [HACKERS] EXISTS optimization
Date: 2007-04-03 21:47:30
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-performance
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, "".

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.


In response to

pgsql-performance by date

Next:From: jason@ohloh.netDate: 2007-04-03 22:13:15
Subject: SCSI vs SATA
Previous:From: Alex DeucherDate: 2007-04-03 21:43:47
Subject: Re: postgres 7.4 vs 8.x redux: query plans

pgsql-hackers by date

Next:From: 4wheelsDate: 2007-04-04 00:37:27
Subject: Finding Queries that have been done on a DB
Previous:From: Tom LaneDate: 2007-04-03 20:51:33
Subject: Re: "Garbled" postgres logs

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group