LIMIT and JOINS

Поиск
Список
Период
Сортировка
Искать

LIMIT and JOINS

От:
"Gregor 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

http://www.torexretail.de

 

Re: LIMIT and JOINS

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Gregor Zeitlinger"  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

FAQ