Re: [SQL] index usage ... strange !?
От | Marten Feldtmann |
---|---|
Тема | Re: [SQL] index usage ... strange !? |
Дата | |
Msg-id | 200001180653.HAA05729@feki.toppoint.de обсуждение исходный текст |
Ответ на | Re: [SQL] index usage ... strange !? (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: [SQL] index usage ... strange !?
|
Список | pgsql-sql |
> Marten Feldtmann <marten@feki.toppoint.de> writes: > > SELECT AO,AT,AV FROM P3AT > > WHERE EXISTS( SELECT AO FROM P3AT WHERE AV='12' AND AT=12 AND CI=17) > > Um ... I dunno what you are trying to accomplish, but this query > almost certainly doesn't do what you want. Since the inner query > is independent of the outer, you will get back either all the rows > of P3AT (if the inner query yields rows) or none (if it doesn't). > > The plan you quote is perfectly reasonable for this query... > the machine is even bright enough to figure out that it only > needs to evaluate the subquery once. > > regards, tom lane > Yes, this seems to be a wrong statement. Actually I would write it like: select AO,AT,AV FROM P3AT WHERE AO IN (SELECT AO FROM P3AT WHERE ...) but as PostgreSQL does not like "IN" very much I rewrote it to the wrongstatement above. select P3AT.AO,P3AT.AT,P3AT.AV FROM P3AT,P3AT as B WHERE (B.AO=P3AT.AO) AND (B.AV='12') AND (B.AT=12) AND (B.CI=17) Therefore I have to rewrite the sql statement above to: SELECT P3AT.AV,P3AT.AT,P3AT.AV FROM P3AT WHEREEXISTS( SELECT B.AO FROM P3AT as B WHERE B.AO=P3AT.AO AND ..... ) Right ? Marten Feldtmann
В списке pgsql-sql по дате отправления: