Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 48936 invoked from network); 8 Mar 2006 19:13:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Mar 2006 19:13:55 -0000 Received: (qmail 82910 invoked by uid 500); 8 Mar 2006 19:13:47 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 82856 invoked by uid 500); 8 Mar 2006 19:13:47 -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 82823 invoked by uid 99); 8 Mar 2006 19:13:47 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Mar 2006 11:13:47 -0800 X-ASF-Spam-Status: No, hits=1.9 required=10.0 tests=DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_POST X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [32.97.182.145] (HELO e5.ny.us.ibm.com) (32.97.182.145) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Mar 2006 11:13:45 -0800 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by e5.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id k28JDNGo027833 for ; Wed, 8 Mar 2006 14:13:23 -0500 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay02.pok.ibm.com (8.12.10/NCO/VER6.8) with ESMTP id k28JDNBV124752 for ; Wed, 8 Mar 2006 14:13:23 -0500 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k28JDNZZ019870 for ; Wed, 8 Mar 2006 14:13:23 -0500 Received: from [127.0.0.1] (sig-9-48-106-125.mts.ibm.com [9.48.106.125]) by d01av03.pok.ibm.com (8.12.11/8.12.11) with ESMTP id k28JDLrT019797 for ; Wed, 8 Mar 2006 14:13:22 -0500 Message-ID: <440F2CC9.4080102@sbcglobal.net> Date: Wed, 08 Mar 2006 11:13:13 -0800 From: Mike Matrigali Reply-To: mikem_app@sbcglobal.net User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Derby Discussion Subject: Re: Derby JDBC Embedded Driver, Prepared Statements, and Indexes References: <004701c642dc$5c4d5c90$dd00a8c0@itsdev.infotechsoft.com> In-Reply-To: <004701c642dc$5c4d5c90$dd00a8c0@itsdev.infotechsoft.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N I believe that no index is actually created on MyTable, only on AnotherTable. From the one query below it seems like you want an index on (fk asc, date_millis desc). But if you run other queries then other indexs may make more sense. I am not sure exactly what is going on with your performance measurements, it has the feel of comparing compile time vs execute time and/or cached table data vs uncached table data. Could you explain exactly how you get your performance measurement, it is clear below with the SQuirreL example but not with the java code. The results have the feel of comparing compile time vs. execution time of a prepared statement and/or cached db vs. not cached db. Note that once a query is compiled it is cached, so you may be saving compile in squirrel without knowing it if you are leaving the db booted and the query was sometime compiled what squirrel. Thomas J. Taylor wrote: > Hi everyone, > > I have a table with 400,000+ records in it and a foreign key (and index) to > a BIGINT value in another table. Through JDBC/Embedded Driver it takes about > 2 seconds to retrieve a single value from the table using a simple SELECT > query as a PreparedStatement. I use a PreparedStatement as I call the query > up to 1,000 times, replacing the values of 'fk' and 'date_millis' during > each call. > > Through SQurrieL, with the same database and Derby Embedded driver, > executing the query takes 15ms. If I drop the foreign key and index, it > takes 8862ms - both times using Derby runtime statistics. > > Does anybody know of a reason that the PreparedStatement is always taking > ~2sec to complete, while SQuirreL takes 15ms to complete a similar query? > > Any help is appreciated. > > Thomas > > > -- Example Table > CREATE TABLE MyTable ( > dbid BIGINT IDENTITY GENERATED BY DEFAULT, > col1 VARCHAR(255), > col2 VARCHAR(255), > date_millis BIGINT NOT NULL, > fk BIGINT, > FOREIGN KEY fk REFERENCES AnotherTable (dbid) > ); > > -- Example Java Code > PreparedStatement pStmt = connection.prepareStatement("SELECT * from MyTable > WHERE fk = ? AND date_millis <= ? ORDER BY date_millis DESC"); > .. > ResultSet rs = pStmt.executeQuery(); > > -- Example SQuirreL SQL Code for stats > CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1); > CALL SYSCS_UTIL.SYSCS_SET_STATISTICS_TIMING(1); > > SELECT * from MyTable WHERE fk = 413689 AND date_millis <= 9999999999999999 > ORDER BY date_millis DESC; > > VALUES SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS(); > CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0); > CALL SYSCS_UTIL.SYSCS_SET_STATISTICS_TIMING(0); > > > >