Received: from sunpine.krs.ru (SunPine.krs.ru [195.161.16.37]) by hub.org (8.9.3/8.9.3) with ESMTP id EAA63130 for ; Mon, 31 May 1999 04:51:30 -0400 (EDT) (envelope-from vadim@krs.ru) Received: from krs.ru (dune.krs.ru [195.161.16.38]) by sunpine.krs.ru (8.8.8/8.8.8) with ESMTP id QAA09802; Mon, 31 May 1999 16:50:52 +0800 (KRSS) Sender: root@sunpine.krs.ru Message-ID: <37524D6A.6B8B50E@krs.ru> Date: Mon, 31 May 1999 16:50:50 +0800 From: Vadim Mikheev Organization: OJSC Rostelecom (Krasnoyarsk) X-Mailer: Mozilla 4.5 [en] (X11; I; FreeBSD 3.0-RELEASE i386) X-Accept-Language: ru, en MIME-Version: 1.0 To: Remigiusz Sokolowski CC: pgsql-sql@postgreSQL.org Subject: Re: [SQL] indexes References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Remigiusz Sokolowski wrote: > > Hi! > I try to optimize following query > SELECT DISTINCT e1.name_ent AS nazwa_grupy > FROM ent e1, binds b1, ent e2 > WHERE e1.id_ent=b1.id_parent AND b1.id_child=e2.id_ent AND b1.id_links=0 ^^^^^^^^^^^^^ > AND e2.name_ent='SERWIS'; > > Is it possible to get better results? From explain notes it looks, that > engine uses indexes on ent table, but I can't constrain it to use any > index on binds table - this causes main problem. > Or may be query should look in other way? > ... > Table = binds2_idx > +--------------------+----------------------------------+------+ > |Field | Type |Length| > +--------------------+----------------------------------+------+ > | id_parent | int4 |4 | > | id_child | int4 |4 | > | id_links | int4 |4 | > +--------------------+----------------------------------+------+ Try to create index on binds (id_links, id_parent, id_child) Vadim