Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id B3D3B632A95 for ; Fri, 27 Mar 2009 13:36:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 17204-01 for ; Fri, 27 Mar 2009 13:36:51 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f169.google.com (mail-bw0-f169.google.com [209.85.218.169]) by mail.postgresql.org (Postfix) with ESMTP id A36A6632521 for ; Fri, 27 Mar 2009 13:36:51 -0300 (ADT) Received: by bwz17 with SMTP id 17so1671523bwz.19 for ; Fri, 27 Mar 2009 09:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=XmMzQqXOlM81kalySizDaEJ/2eSOvNLiHeWaW91Qu8s=; b=W2HjAcP0mOBpNXVOuCbM1y6boFbzFA+dJ4elI/UlDqOhoZcAiEwccje3BMYXfR8sM+ nLjq5osPTNtBU/0jObIt8v4ILy6QycpgWrHKLdh3E42HckfR0GB6NuSt7OQgQsxClS/s OxuhBVFwA+COoayKlJYfCylQ/GaHc72UYmg9Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=BlxHv3AXM9bLRIblsHq7vSVtY0qcWwH/xYEEbVRvNPBaKOUsQ3vAMPhcVSUTt6Hbre FIGUyyi/zzlEvJg5rgVaP5YdYwTYEhClUbyhhDPy59Q70phrnhWRuYljvFk5IjZ8lLSj 0XSQszHpJa1K7ceCGFYhMa5MUSEfNWzIvJ4zk= MIME-Version: 1.0 Received: by 10.103.228.7 with SMTP id f7mr520594mur.0.1238171810105; Fri, 27 Mar 2009 09:36:50 -0700 (PDT) In-Reply-To: References: Date: Fri, 27 Mar 2009 18:36:50 +0200 Message-ID: <331e40660903270936u5db00807sb1169df66443ade3@mail.gmail.com> Subject: Re: Very specialised query From: =?KOI8-U?B?96bUwcymyiD0yc3eydvJzg==?= To: Matthew Wakeling Cc: pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary=001636920095e98aba04661c5697 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200903/392 X-Sequence-Number: 33314 --001636920095e98aba04661c5697 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hello. You could try adding "AND l2.start > l1.start" to the first query. This will drop symmetric half of intersections (the ones that will remain are l2 inside or to the left of l1), but you can redo results by id1,id2 union all id2, id1 and may allow to use start index for "between", for my "like" test this looks like the next: " -> Index Scan using location__start on location l2 (cost=0.00..756.34 rows=37787 width=12)" " Index Cond: ((l2.start < l1.eend) AND (l2.start > l1.start))" also an index on (objectid, start) would help resulting in : " -> Index Scan using lt on location l2 (cost=0.00..0.84 rows=20 width=16)" " Index Cond: ((l2.objectid = l1.objectid) AND (l2.start < l1.eend) AND (l2.start > l1.start))" Best regards, Vitalii Tymchyshyn --001636920095e98aba04661c5697 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello.

You could try=A0 adding =A0=A0 "AND l2.start > l1.sta= rt" to the first query.=A0 This will drop symmetric half of intersecti= ons (the ones that will remain are l2 inside or to the left of l1), but you= can redo results by
id1,id2 union all id2, id1 and may allow to use start index for "betwe= en",=A0 for my "like" test this looks like the next:

= "=A0 ->=A0 Index Scan using location__start on location l2=A0 (cost= =3D0.00..756.34 rows=3D37787 width=3D12)"
"=A0=A0=A0=A0=A0=A0=A0 Index Cond: ((l2.start < l1.eend) AND (l2.st= art > l1.start))"

also an index on (objectid, start) would h= elp resulting in :

"=A0 ->=A0 Index Scan using lt on locatio= n l2=A0 (cost=3D0.00..0.84 rows=3D20 width=3D16)"
"=A0=A0=A0=A0=A0=A0=A0 Index Cond: ((l2.objectid =3D l1.objectid) AND = (l2.start < l1.eend) AND (l2.start > l1.start))"

Best reg= ards,
=A0Vitalii Tymchyshyn
--001636920095e98aba04661c5697--