Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 1E958B5DC19 for ; Sat, 29 Oct 2011 18:04:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 36840-10 for ; Sat, 29 Oct 2011 21:04:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from nm29-vm1.bullet.mail.ne1.yahoo.com (nm29-vm1.bullet.mail.ne1.yahoo.com [98.138.90.63]) by mail.postgresql.org (Postfix) with SMTP id 2E76EB5DC0F for ; Sat, 29 Oct 2011 18:04:15 -0300 (ADT) Received: from [98.138.90.51] by nm29.bullet.mail.ne1.yahoo.com with NNFMP; 29 Oct 2011 21:04:14 -0000 Received: from [98.138.84.37] by tm4.bullet.mail.ne1.yahoo.com with NNFMP; 29 Oct 2011 21:04:14 -0000 Received: from [127.0.0.1] by smtp105.mail.ne1.yahoo.com with NNFMP; 29 Oct 2011 21:04:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1319922254; bh=GyxfKkYSmgL8sT3r/eyhOz6ICjpGLj/ckolVqtv5vMU=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:Subject:Mime-Version:Content-Type:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=QIjE2Q/i5wxxN1NoMCzaIfF0dv3ao6Vo/ggrSF63k5YwY7wlymtV4QFhZ/q+GWirYn4HpXg4t0KJyT/O7v2wpQx8qJKIGOBVxihoVkhoyq9MdPJuXqenI1xejRdLnFF+qnmYkMkWC3f4qxVgdlfKSKxhr6+6iP5DcBQkC5HXLDc= X-Yahoo-Newman-Id: 113878.47914.bm@smtp105.mail.ne1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: r6QOZqEVM1nJXO07DK38JQJCaWa_xkwItdohW2.V1Ly0kbL Gjg4ek3IShUE5PTquag3g1IHgF_zgIHW30I4eMkTyTiAVKgdGrIVcsudxGUy dnEdyfx2DzY.wkwUmZQQyQ8WjIaraGSjGMhuDCyGBxWbHNTXUU6mhzRnm6LS _wqwt6Dg5hJREyNDlYeTGbrOpsgvGgd1p7F_L1B6a4j2.tyIEm6k5_Q4ZcxA mgd2SHGD3tfKNatrDraABe9IHJtzZ3H0GKgrLHkH4bqw9pX0dY5tyQKpptIo Cnd97.jHs.M2YQl9QyI73gdkuYrodJy7UP79PL18bRydrLlFmJjoRQ43iJ4i H.y1fBzwKtjCHs8bjHMhH5s4aBQvA5mhP.4cJHN320O_XI_3l.tc6M0I5spv xIrx0b299Tg-- X-Yahoo-SMTP: xViJEQuswBDS3VwguObYPN4pupI- Received: from [192.168.1.101] (tybusby@72.230.216.254 with plain) by smtp105.mail.ne1.yahoo.com with SMTP; 29 Oct 2011 14:04:13 -0700 PDT Subject: Re: optimize self-join query Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset=us-ascii From: Ty Busby In-Reply-To: Date: Sat, 29 Oct 2011 17:04:11 -0400 Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Ty Busby X-Mailer: Apple Mail (2.1251.1) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.403 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201110/88 X-Sequence-Number: 35972 Thanks to everyone for all the thoughtful responses. They have been = incredibly helpful. Ended up optimizing per Lee, and creating buckets per Tom. Thanks = again. On Oct 25, 2011, at 2:37 PM, Ty Busby wrote: I have a table that stores a very large starting number called = epc_start_numeric and a quantity. I've apparently built the most = inefficient query possible for doing the job I need: find out if any = records overlap. Imagine the epc_start_numeric + quantity representing = a block of numbers. I need to find out if any of these blocks overlap.