Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 82713 invoked from network); 4 Aug 2009 14:17:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Aug 2009 14:17:02 -0000 Received: (qmail 15552 invoked by uid 500); 4 Aug 2009 14:17:06 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 15475 invoked by uid 500); 4 Aug 2009 14:17:06 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 15467 invoked by uid 99); 4 Aug 2009 14:17:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Aug 2009 14:17:06 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [63.82.107.6] (HELO red.amberpoint.com) (63.82.107.6) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Aug 2009 14:16:57 +0000 Received: from [127.0.0.1] (bp-laptop.edgility.com [10.10.12.207]) by red.amberpoint.com (8.13.8/8.13.8) with ESMTP id n74EGXC1017731 for ; Tue, 4 Aug 2009 07:16:34 -0700 Message-ID: <4A7842C1.2030800@amberpoint.com> Date: Tue, 04 Aug 2009 07:16:33 -0700 From: Bryan Pendleton User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: Derby Discussion Subject: Re: Filtering using the sort order on two columns References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Daniel Noll wrote: > SELECT field, text, docfreq > FROM Terms > WHERE (field = ? AND text > ?) OR field > ? > ORDER BY field ASC, text ASC > > This does the right thing as far as the output is concerned, but Derby > does a table scan. What happens if you do two separate queries: SELECT field, text, docfreq FROM Terms WHERE field > ? ORDER BY field ASC, text ASC SELECT field, text, docfreq FROM Terms WHERE (field = ? AND text > ?) ORDER BY field ASC, text ASC Sometimes the "OR" will really throw off the optimizer. Does each query, separately, use the index as you expect? thanks, bryan