Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 10196 invoked from network); 17 Jun 2005 02:49:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Jun 2005 02:49:33 -0000 Received: (qmail 8254 invoked by uid 500); 17 Jun 2005 02:49:32 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 8209 invoked by uid 500); 17 Jun 2005 02:49:31 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 8186 invoked by uid 99); 17 Jun 2005 02:49:30 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=FORGED_RCVD_HELO,TO_ADDRESS_EQ_REAL X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from 68-97-89-203-static.vic.ipn.net.au (HELO conads.com) (203.89.97.68) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2005 19:49:30 -0700 Received: from [220.244.112.202] (account zoran HELO [10.0.1.3]) by conads.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 424011 for user-java@ibatis.apache.org; Fri, 17 Jun 2005 11:46:34 +1000 User-Agent: Microsoft-Entourage/11.1.0.040913 Date: Fri, 17 Jun 2005 11:46:35 +1000 Subject: OT: COUNT query speed issue From: Zoran Avtarovski To: "user-java@ibatis.apache.org" Message-ID: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N I have a quick query regarding the speed of count query I use to generate a chart, which is too slow at present and I'm looking for suggestions to speed it up. I pass a collection of the last 30 days data usage to a simple Flash charting app and I use the ibatis query below in a loop thirty times to get the data for each successive day. The table has about half a million entries and will only be getting bigger. SELECT COUNT(*) AS count FROM log WHERE remote_id = #remoteId# and log_time BETWEEN #lowDate# AND #highDate# The complete query (all thirty days) takes over a minute to complete, which causes timeouts. I did some profiling and the bottle neck is with the above query. Clearly, I'm doing something wrong. Is there a better formed query that will improve speed or should I be looking at a different approach to this issue? I know this sounds stupid but I'm looking for pointers for best practice so I don't have to revisit this issue down the track. Zoran