Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 77B0ED039 for ; Sat, 22 Dec 2012 18:10:33 +0000 (UTC) Received: (qmail 81800 invoked by uid 500); 22 Dec 2012 18:10:33 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 81772 invoked by uid 500); 22 Dec 2012 18:10:33 -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 81765 invoked by uid 99); 22 Dec 2012 18:10:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Dec 2012 18:10:33 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of john.foreign@gmail.com designates 74.125.83.47 as permitted sender) Received: from [74.125.83.47] (HELO mail-ee0-f47.google.com) (74.125.83.47) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Dec 2012 18:10:01 +0000 Received: by mail-ee0-f47.google.com with SMTP id e51so2934543eek.20 for ; Sat, 22 Dec 2012 10:09:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=zn3HX3tiYmVBlfTHHpiKv7D3u1FML4HJR9xntv2aEBo=; b=UMEdFqf11IA63ARmr4VNJ97Hx2e7ZjQO0kduFQ9OG1ZpYzDSxp1co6TWol39KFZifo 96TY0ba7FiPl69DUqAymk+lQ/K00dekYUYRnEyCbcX7FowNlMEznRULk/QSGVlaPsh50 qStWcC3eDLh/eJ3elmeSzxL6TRz9tT4Hh5B8xgvVU0JLfWG66zY97zPUCSdF/yEWJ+0F N08xVzRhknCA9I/qMzGo1HlGN8f4ZTEOhPhKa9XBXzmDPeD3/V7Kh7jwaX41WLt4j+Jd I/LE4/OX9L3JgH64sXMmqMYKts+I8gHS7U+LuVUAPFPwBi/pgbEnd2rwYlOy6wbt14W1 DGOQ== X-Received: by 10.14.202.3 with SMTP id c3mr42036595eeo.4.1356199780404; Sat, 22 Dec 2012 10:09:40 -0800 (PST) Received: from [192.168.1.101] (bzq-84-108-22-132.cablep.bezeqint.net. [84.108.22.132]) by mx.google.com with ESMTPS id b2sm29616063eep.9.2012.12.22.10.09.39 (version=SSLv3 cipher=OTHER); Sat, 22 Dec 2012 10:09:39 -0800 (PST) Message-ID: <50D5F75D.60109@gmail.com> Date: Sat, 22 Dec 2012 20:09:33 +0200 From: John English User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Derby Discussion Subject: Re: Ideas for optimisation needed References: <50D2FACF.7080308@gmail.com> <50D45FAE.9070502@gmail.com> <87a9t7b8xk.fsf@oracle.com> In-Reply-To: <87a9t7b8xk.fsf@oracle.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 21/12/2012 19:40, Knut Anders Hatlen wrote: > Does it change anything if you access the table directly instead of via > the view? I think we've had reports that the optimizer cannot always see > through the views and misses out on some opportunities for optimization. Aha; what seems to happen is that in order to count the number of rows it reads though the entire result set from the view, which seems to involve formatting every single row... I've ended up basically rewriting most of the code involved; I now count the rows in a separate query (as suggested earlier by Jean-Yves Linet), which allows me to use an offset/fetch clause (which are new in Derby since this code was originally written). The change in timing is spectacular: it now takes about 0.4 seconds if I only want the first 20 rows, which is about 50 times faster than before. So, problem solved it seems; many thanks for the advice! -- John English