Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 9A0CB1337B54 for ; Fri, 11 Feb 2011 05:44:15 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 83964-05 for ; Fri, 11 Feb 2011 09:44:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f46.google.com (mail-bw0-f46.google.com [209.85.214.46]) by mail.postgresql.org (Postfix) with ESMTP id B68FB1337B82 for ; Fri, 11 Feb 2011 05:44:07 -0400 (AST) Received: by bwz15 with SMTP id 15so3022073bwz.19 for ; Fri, 11 Feb 2011 01:44:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=UVIm7S5UxNEOfMV/WX8s0/ZligWyVa799FrQadu869E=; b=GFr6yTkIlPg4f0HUNa2d9lHm3hT6ZtfagsGu3c3kLP7KoeLDwXESHgDFRz2XaHem8A Tau5o3eVWPv/qMTkliT1cOoVAi4jbVLrHOTpUybJn5IxXz5N79rFt/4QPMUkI5PA1pFk wT/d3MSlKIveAFTtIqivh+xsYs3qDxhhtE7r0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=qtPWx8Qd6iZH7p4POii4u/0ybDuuUuQgbTGflPZAjIPPdYzJNIMihHem2XaCszaZX4 SRNPfGCkEDOogCFhVEMBytlr55snuw0qrpcLzPspIRn8aK1QW79CszaGp3AGBsGH84oz Ld7iwiRlT2dtOYnLrnr+laJ2RP4D/cV628dDw= Received: by 10.204.65.135 with SMTP id j7mr261420bki.85.1297417446958; Fri, 11 Feb 2011 01:44:06 -0800 (PST) Received: from [10.1.1.57] (skuns.zoral.com.ua [91.193.166.194]) by mx.google.com with ESMTPS id x38sm327160bkj.13.2011.02.11.01.44.05 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 Feb 2011 01:44:06 -0800 (PST) Message-ID: <4D5504E5.3060901@gmail.com> Date: Fri, 11 Feb 2011 11:44:05 +0200 From: Vitalii Tymchyshyn User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: Tobias Brox CC: Josh Berkus , pgsql-performance@postgresql.org, Mladen Gogala Subject: Re: Why we don't want hints Was: Slow count(*) again... References: <201102012247.p11Ml6u02682@momjian.us> <4D48914B.4050403@dunslane.net> <4D489AD1.1010105@vmsinfo.com> <4D499E55.4020107@vmsinfo.com> <4D49A6B9.4060608@2ndquadrant.com> <4D49C482.4010707@vmsinfo.com> <4D49F0BA.9000901@2ndquadrant.com> <4D4A16BF.1020304@vmsinfo.com> <4D4A4844.3020409@2ndquadrant.com> <4D4AD9F6.6040903@vmsinfo.com> <4D4AE16E.9040807@peak6.com> <4D4B17B4.9030406@vmsinfo.com> <4D4B1F5B.4060403@peak6.com> <4D4B261B.6010303@vmsinfo.com> <4D4B2E8A.7010402@vmsinfo.com> <4D4B3395.6010007@agliodbs.com> <4D4B394E.9080505@vmsinfo.com> <4D4B5A73.3080302@agliodbs.com> In-Reply-To: Content-Type: text/plain; charset=KOI8-U; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.046 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=1.553, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201102/347 X-Sequence-Number: 42485 11.02.11 11:29, Tobias Brox написав(ла): > 2011/2/11 В╕тал╕й Тимчишин: >> If the list is hard-coded, you can create partial index on >> account_transaction(account_id, created desc) where trans_type_id in ( ... >> long, hard-coded list ...) > My idea as well, though it looks ugly and it would be a maintenance > head-ache (upgrading the index as new transaction types are added > would mean "costly" write locks on the table, Create new one concurrently. > and we can't rely on > manual processes to get it right ... we might need to set up scripts > to either upgrade the index or alert us if the index needs upgrading). Yep. Another option could be to add query rewrite as select * from ( select * from account_transaction where trans_type_id =type1 and account_id=? order by created desc limit 25 union all select * from account_transaction where trans_type_id =type2 and account_id=? order by created desc limit 25 union all ... union all select * from account_transaction where trans_type_id =typeN and account_id=? order by created desc limit 25 ) a order by created desc limit 25 This will allow to use three-column index in the way it can be used for such query. Yet if N is large query will look ugly. And I am not sure if optimizer is smart enough for not to fetch 25*N rows. Best regards, Vitalii Tymchyshyn