Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 83703 invoked from network); 11 Feb 2008 23:49:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Feb 2008 23:49:38 -0000 Received: (qmail 53958 invoked by uid 500); 11 Feb 2008 23:49:30 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 53672 invoked by uid 500); 11 Feb 2008 23:49:30 -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 53661 invoked by uid 99); 11 Feb 2008 23:49:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Feb 2008 15:49:30 -0800 X-ASF-Spam-Status: No, hits=-2.8 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: 32.97.110.152 is neither permitted nor denied by domain of qozinx@gmail.com) Received: from [32.97.110.152] (HELO e34.co.us.ibm.com) (32.97.110.152) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Feb 2008 23:48:44 +0000 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e34.co.us.ibm.com (8.13.8/8.13.8) with ESMTP id m1BNn2j9025818 for ; Mon, 11 Feb 2008 18:49:02 -0500 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id m1BNn2dS193870 for ; Mon, 11 Feb 2008 16:49:02 -0700 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m1BNn2XF027886 for ; Mon, 11 Feb 2008 16:49:02 -0700 Received: from [127.0.0.1] (svl-arbrown1.svl.ibm.com [9.30.146.59]) by d03av03.boulder.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id m1BNn17w027838 for ; Mon, 11 Feb 2008 16:49:02 -0700 Message-ID: <47B0DEFE.6060905@gmail.com> Date: Mon, 11 Feb 2008 15:49:18 -0800 From: Army User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Derby Discussion Subject: Re: COUNT() optimisation References: <200802080925.35160.daniel@nuix.com> <47ACADBD.3030603@gmail.com> <200802111010.35312.daniel@nuix.com> In-Reply-To: <200802111010.35312.daniel@nuix.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Daniel Noll wrote: > > I created bogus test data where jobid was always 0 and state was > cycled between 0,1,2. > > Query: > SELECT COUNT(*) FROM jobitems WHERE jobid = 0 AND state = 0 Given this particular query pattern I would say that increased times for larger tables makes sense. Since jobid is always 0 and state has one of three values, if you increase the number of rows from 100 to 1 million it stands to reason that there are going to be a lot more rows matching the WHERE criteria, and so it will take longer to count those rows. For the record, when I changed the data and the WHERE clause so that COUNT(*) only returns a single row, the times I saw were constant regardless of how many rows were in the table--which is what I would expect since we're using the index. > If I log the query plan it confirms what's happening. It estimates > the number of rows which will come back and then says it's iterating > through each row to determine the count. Okay, I think that matches what I mentioned above... > Problem is that two users adding or removing items at the same time > would be updating the same table and I'm not sure how clever Derby is > if two users do an UPDATE at the same time which adds or subtracts > from the existing value. Unless I'm missing the heart of your question, I think this is a fairly normal transactional task for Derby: two users trying to update the same row at the same time. Derby should use transaction locking to ensure that both users' updates are correctly reflected in the table. > If it merged them together as expected then I'm guessing would be > a viable solution. I agree, it seems like that should work (assuming "merge" here means "correctly apply both users' changes to the table"). If you try it out and run into problems, though, you can always post back with a follow-up mail... Army