<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - wykorzystanie indeksu przy podzapytaniu]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=40&amp;type=atom"/>
	<updated>2009-06-16T17:11:50Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=40</id>
		<entry>
			<title type="html"><![CDATA[Odp: wykorzystanie indeksu przy podzapytaniu]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=998#p998"/>
			<content type="html"><![CDATA[A jaki index jest zdefiniowany?  Może pokazałbyś plany zapytań. 'Odświeżyłeś' statystyki?]]></content>
			<author>
				<name><![CDATA[rski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=26</uri>
			</author>
			<updated>2009-06-16T17:11:50Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=998#p998</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: wykorzystanie indeksu przy podzapytaniu]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=995#p995"/>
			<content type="html"><![CDATA[mam podobny problem

znalazłeś może rozwiązanie lub cokolwiek]]></content>
			<author>
				<name><![CDATA[heban]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=929</uri>
			</author>
			<updated>2009-06-16T14:52:09Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=995#p995</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[wykorzystanie indeksu przy podzapytaniu]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=146#p146"/>
			<content type="html"><![CDATA[Witam

Mam dwie tabele, które mają zdefiniowane indeksy. 

tabela1 (
id serial,
pole1 varchar(10),
....
)
indeks na id.

oraz

tabela2 (
indeksowane_pole varchar(10),
opis varchar(50)
)
indeks na indeksowane_pole

Przy tworzeniu zapytania z join po indeksowanej kolumnie np.:

select tabela1.id, tabela1.pole1, tabela2.opis from tabela1 left join tabela2 on (tabela1.pole1 = tabela2.indeksowane_pole);

Komenda EXPLAIN ANALYZE wskazuje, że indeks jest wykorzystywany, czyli wszystko ok. 

Problem pojawia sie w podzapytaniu np. takim:

select tabela1.id, tabela1.pole23, (select tabela2.opis from tabela2 where tabela2.indeksowane_pole = tabela1.pole1) as 'COS' 
  from tabela1;

W takim przypadku EXPLAIN ANALYZE wskazuje ze select z tabeli2 nie wykorzystuje indeksu tylko sprawdza tabelę sekwencyjnie. Niestety nie mogę użyć joina. Czy ktoś może mi poradzić jaki indeks powinien być zdefiniowany na tabeli2?]]></content>
			<author>
				<name><![CDATA[lesny]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=98</uri>
			</author>
			<updated>2008-05-16T07:26:54Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=146#p146</id>
		</entry>
</feed>
