Seemingly identical queries run at different speeds

From: VanL <vlindberg(at)verio(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Seemingly identical queries run at different speeds
Date: 2003-07-22 23:27:37
Message-ID: bfkh0r$iri$1@main.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I have three queries that are essentially identical. Two of them run in
fractions of a second; one of them takes longer than 15 minutes to
return. (Not sure how long it totally takes, that has been the limit of
my patience.)

The only difference between these queries is the use of table aliases in
the sql query. What is happening in postgres that this makes such a
difference?

SQL queries below.

Thanks,

VanL

FAST (0.017 second):
select
mm_batch.name as batch_name,
mm_domain.name as domain_name,
mm_management_unit.name as management_unit_name,
mm_customer.firstname as customer_name,
mm_legacy_account.username as old_username,
mm_target_account.username as new_username
from
mm_batch,
mm_domain,
mm_management_unit,
mm_customer,
mm_legacy_account,
mm_target_account
where
mm_domain.bid = mm_batch.id
and mm_domain.mid = mm_management_unit.id
and mm_domain.cid = mm_customer.id
and mm_domain.lid = mm_legacy_account.id
and mm_domain.tid = mm_target_account.id
and mm_domain.name = 'example.com';
========================================================
FAST (0.016 second):
select
B.name as batch_name,
D.name as domain_name,
M.name as management_unit_name,
C.firstname as customer_name,
LA.username as old_username,
TA.username as new_username
from
mm_batch B,
mm_domain D,
mm_management_unit M,
mm_customer C,
mm_legacy_account LA,
mm_target_account TA
where
D.bid = B.id
and D.mid = M.id
and D.cid = C.id
and D.lid = LA.id
and D.tid = TA.id
and D.name = 'example.com';
=========================================================
SLOW ( > 15 minutes):
select
mm_batch.name as batch_name,
mm_domain.name as domain_name,
mm_management_unit.name as management_unit_name,
mm_customer.firstname as customer_name,
mm_legacy_account.username as old_username,
mm_target_account.username as new_username
from
mm_batch B,
mm_domain D,
mm_management_unit M,
mm_customer C,
mm_legacy_account LA,
mm_target_account TA
where
mm_domain.bid = mm_batch.id
and mm_domain.mid = mm_management_unit.id
and mm_domain.cid = mm_customer.id
and mm_domain.lid = mm_legacy_account.id
and mm_domain.tid = mm_target_account.id
and mm_domain.name = 'example.com';

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Arguile 2003-07-23 01:06:11 Re: Seemingly identical queries run at different speeds
Previous Message Jonathan Bartlett 2003-07-22 21:22:19 Re: [GENERAL] Making pg_dump cvs friendly