Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 35123 invoked from network); 18 Sep 2008 19:00:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Sep 2008 19:00:57 -0000 Received: (qmail 33330 invoked by uid 500); 18 Sep 2008 19:00:52 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 33313 invoked by uid 500); 18 Sep 2008 19:00:52 -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 Delivered-To: moderator for derby-user@db.apache.org Received: (qmail 91299 invoked by uid 99); 15 Sep 2008 00:39:37 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of opencoeli@gmail.com designates 66.249.92.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:reply-to:to :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=wpBoQn3VwzFaa2ewIv2dAghJpbWQwkTLN3GkGmw3G7g=; b=TtwneDCuZambEm6cy7VVYm1Lkp6n1Ss2azXYxQwW2OHGyWOSiqAimo1FJJ+zoUvSxA /7wxPdEN8t0xCoaUiAeQyKs6ssYz1pmHZ4BE6r5QYI8FsE4fP1JFVwB/dcpNl4hoAbbj 0LTV+lnrZww5zz8oHEizYh2UUWX7RY2R6yRlw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:reply-to:to:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=Hmu4Qet81GRdjJWlyVfFpvSkg/cHbnKoDC9xMVTRudMEWdzI7MizD9xrX/IR6O25gD Rz6pn7JvK2FvWJUpoZDO+OJ/7TelFCkrzuWWMFdbzKLkRrNlrUiUURS5sANJXL5+9niQ Kf489W1eiDEiux+R1gADpK/TFzxAirUzEvRzQ= Subject: Index not used for complex WHERE From: Jan Kotek Reply-To: opencoeli@gmail.com To: derby-user@db.apache.org Content-Type: text/plain Date: Mon, 15 Sep 2008 01:39:04 +0100 Message-Id: <1221439144.8279.16.camel@artemis> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hello, it seems to me that Derby is not using index for more complex WHERE cause. Table have only 3 colums, all number. There is only one index on IPIX column (BIGINT). There is ~100000 records in table. With simple query: SELECT obj FROM MilkyWayPixel obj WHERE (obj.ipix BETWEEN 15284 AND 33739) result is returned immediately (0.1s). But with more complex query it takes around 3 seconds. This time also grows with number of records. And it did not change if there is index on IPIX or not. Derby is clearly not using index in this case. Instead it makes full table scan. Is there any way how I can optimalize query? Complex query where index is not used: SELECT obj FROM MilkyWayPixel obj WHERE (obj.ipix BETWEEN 15284 AND 33739) AND obj.ipix NOT BETWEEN 15308 AND 15535 AND obj.ipix NOT BETWEEN 15569 AND 15789 AND obj.ipix NOT BETWEEN 32468 AND 32684 AND //snip, 50 lines in total... obj.ipix NOT BETWEEN 32723 AND 32941 AND obj.ipix NOT BETWEEN 32979 AND 33197 AND obj.ipix NOT BETWEEN 33234 AND 33455 AND obj.ipix NOT BETWEEN 33489 AND 33715 Thanks for advices. Jan Kotek http://kotek.net/opencoeli