LIMIT and JOINS

Started by Gregor Zeitlingeralmost 20 years ago2 messages
#1Gregor Zeitlinger
gregor.zeitlinger@torexretail.de

Hi,

I have a question on implementation of the LIMIT SQL clause.

Using the LIMIT clause, I want to reduce the computation time for a query.

When I try to limit the result of a joined table, however, the join will be computed first (which takes very long).

Lets suppose the following example:

select * from T1 join T2 on T1.id = T2.id LIMIT 1

Conceptually, it should be possible to fetch one row from T1 and T2, i.e. to propagate the LIMIT clause.

I was wondering what the exact requirements are to propagate the LIMIT clause.

Do I need a foreign key relation between T1 and T2?
Do I need to use a full outer join in order to propagate the LIMIT clause?

Thanks

Gregor Zeitlinger
LUCAS Product Development

Torex Retail Solutions GmbH

Schwedenstr. 9, D-13359 Berlin
Tel. +49 (0) 30 49901-243
Fax +49 (0) 30 49901-139

Mailto:gregor.zeitlinger@torexretail.de <mailto:gregor.zeitlinger@torexretail.de>
http://www.torexretail.de <http://www.torexretail.de/&gt;

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gregor Zeitlinger (#1)
Re: LIMIT and JOINS

"Gregor Zeitlinger" <gregor.zeitlinger@torexretail.de> writes:

select * from T1 join T2 on T1.id =3D T2.id LIMIT 1

Conceptually, it should be possible to fetch one row from T1 and T2, =
i.e. to propagate the LIMIT clause.

I was wondering what the exact requirements are to propagate the LIMIT =
clause.

Indexes would help ...

regards, tom lane