Re: not using table aliases in where clause slow-down?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Mark Cowlishaw <markc(at)ot(dot)com(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: not using table aliases in where clause slow-down?
Date: 2001-02-19 21:10:43
Message-ID: Pine.BSF.4.21.0102191308110.84309-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Mon, 19 Feb 2001, Mark Cowlishaw wrote:

>
> I noticed that running queries that do -not- use declared table aliases in
> the 'where' clause seem to run a hell-of-a-lot slower than when aliases are
> used. Is there a valid reason for this? It started out as a typo but now I'm
> curious.

Well, sort of. Technically the second query is invalid (you cannot use
the non-aliased name if you've aliased IIRC), but postgres assumes that
you really wanted additional from entries for the tables you are using
to make it valid, so:
> select
> rel.release_id as rel_id, rel.code as rel_code,
> subs.subsystem_id as subs_id, subs.code as subs_code,
> func.function_id as func_id, func.code as func_code,
> purp.purpose_id as purp_id, purp.code as purp_code,
> purp.title as purp_title,
> proc.procedure_id as proc_id, proc.code as proc_code,
> proc.title as proc_title
> from
> releases as rel, subsystems as subs,
> functions as func, purposes as purp, procedures as proc
> where
> releases.project_id = 53
> and purposes.release_id = releases.release_id
> and purposes.function_id = functions.function_id
> and functions.subsystem_id = subsystems.subsystem_id
> and purposes.purpose_id = procedures.purpose_id
> order by
> rel.code, subs.code, func.code,
> purp.code, proc.code;

is really:

select
rel.release_id as rel_id, rel.code as rel_code,
subs.subsystem_id as subs_id, subs.code as subs_code,
func.function_id as func_id, func.code as func_code,
purp.purpose_id as purp_id, purp.code as purp_code,
purp.title as purp_title,
proc.procedure_id as proc_id, proc.code as proc_code,
proc.title as proc_title
from
releases as rel, subsystems as subs,
functions as func, purposes as purp, procedures as proc,
***
releases, functions, subsystems, purposes, procedures
***
where
releases.project_id = 53
and purposes.release_id = releases.release_id
and purposes.function_id = functions.function_id
and functions.subsystem_id = subsystems.subsystem_id
and purposes.purpose_id = procedures.purpose_id
order by
rel.code, subs.code, func.code,
purp.code, proc.code;

which is a much different query

In response to

Browse pgsql-general by date

  From Date Subject
Next Message adb 2001-02-19 22:25:35 max / min explain
Previous Message Stephan Szabo 2001-02-19 21:07:32 Re: Foreign keys