Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 1281C1337BCB for ; Fri, 11 Feb 2011 07:26:29 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 62198-01-10 for ; Fri, 11 Feb 2011 11:26:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) by mail.postgresql.org (Postfix) with ESMTP id C02B71337BC8 for ; Fri, 11 Feb 2011 07:26:21 -0400 (AST) Received: by qyk12 with SMTP id 12so1978694qyk.19 for ; Fri, 11 Feb 2011 03:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=oOO/zEnS+9QN+3VBqdupYDM8UEAFqKx0iFETo8aihjg=; b=OaqMgtJP4v/9XSSLwVX3vG3nfRa/n4R7hNcQaPBz85wPXmTYEN9m2T6mB17YC40E3o 2km+zOBwErlmcic2KRZfOigw3EjniFpVqH4m5IxG++dbrYJf0hZPUE3AjDLCv8xOcUIj zfR64IAnun1UZs6tqlHISrCp6nKmoBGontbjc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=gQH4GMGFlg34zt8GZp0bEMVnaIhekto5d3kkxT/lBdRemdQnQm73GM8LOCbePc4rwY 7QeUScSRI/LBuWr9Ncm6RZbrgM+zG9qC32+cJy3TcvnhfQkUHz9fgNx5urgIRJVRCEpr h+tj+Ngv0nqL+KeJSTeS1Jc/qPkjYBwaGBmIo= Received: by 10.229.214.10 with SMTP id gy10mr403304qcb.130.1297423581729; Fri, 11 Feb 2011 03:26:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.223.203 with HTTP; Fri, 11 Feb 2011 03:26:01 -0800 (PST) In-Reply-To: <4D5504E5.3060901@gmail.com> 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> <4D5504E5.3060901@gmail.com> From: Tobias Brox Date: Fri, 11 Feb 2011 14:26:01 +0300 Message-ID: Subject: Re: Why we don't want hints Was: Slow count(*) again... To: Vitalii Tymchyshyn Cc: Josh Berkus , pgsql-performance@postgresql.org, Mladen Gogala Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201102/348 X-Sequence-Number: 42486 2011/2/11 Vitalii Tymchyshyn : >> 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. Concurrently? Are there any ways to add large indexes without blocking inserts to the table for the time it takes to create the index? > Yep. Another option could be to add query rewrite as > > select =A0* from ( > select * from account_transaction where trans_type_id =3Dtype1 and > account_id=3D? order by created desc limit 25 union all > select * from account_transaction where trans_type_id =3Dtype2 and > account_id=3D? order by created desc limit 25 union all > ... > union all > select * from account_transaction where trans_type_id =3DtypeN and > account_id=3D? order by created desc limit 25 > ) a > order by created desc limit 25 I actually considered that. For the test case given it works very fast. Not sure if it would work universally ... it scales well when having extreme amounts of transactions outside the given transaction list (the case we have problems with now), but it wouldn't scale if some user has an extreme amount of transactions within the list. However, I think our "extreme amount of transactions"-problem is mostly limited to the transaction types outside the list.