Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id F1880B5DBD8 for ; Wed, 14 Sep 2011 12:28:49 -0300 (ADT) 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 25989-07 for ; Wed, 14 Sep 2011 15:28:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com [209.85.161.46]) by mail.postgresql.org (Postfix) with ESMTP id 702BBB5D91F for ; Wed, 14 Sep 2011 12:28:42 -0300 (ADT) Received: by fxe4 with SMTP id 4so1854173fxe.19 for ; Wed, 14 Sep 2011 08:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; 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; bh=5/wSy5D9n6QmgCn2KEdmiy9Zar9xTi4m8dDzB3goHHc=; b=V/deL8y1PRiRvU4XGMFOdQiXPyfWQLqEj6liU5gR/EBfAtfXNUZK33sbJOiv8ZSSyB NgiV0zpjhT2grLXFFjjMfIc8pfZ1/HvMlUzs7WDrB9qoNLCd0YbxC7H0/T/xeHy/rLqR uPra0uZl8yPrxNfVZWbdsxVlxAMp1iYtqxqLo= Received: by 10.223.9.154 with SMTP id l26mr923287fal.36.1316014121366; Wed, 14 Sep 2011 08:28:41 -0700 (PDT) Received: from [10.64.1.26] ([94.45.140.16]) by mx.google.com with ESMTPS id c2sm3686170faf.16.2011.09.14.08.28.39 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Sep 2011 08:28:40 -0700 (PDT) Message-ID: <4E70C826.1050800@gmail.com> Date: Wed, 14 Sep 2011 18:28:38 +0300 From: Vitalii Tymchyshyn User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 MIME-Version: 1.0 To: MirrorX CC: pgsql-performance@postgresql.org Subject: Re: cannot use multicolumn index References: <1316004607207-4802634.post@n5.nabble.com> <1316005753084-4802699.post@n5.nabble.com> <0ac4fa43876e63ec84515656f233960f.squirrel@sq.gransy.com> <1316013240443-4803198.post@n5.nabble.com> In-Reply-To: <1316013240443-4803198.post@n5.nabble.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.799 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=0.1, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201109/216 X-Sequence-Number: 44992 14.09.11 18:14, MirrorX написав(ла): > i think in my first post i provided most of these details but -> > 1) what i expect is to be able to understand why the index is not used and > if possibly to use it somehow, or recreate it in a better way > 2) the table has 115 GB and about 700 milion rows > 3) the result should be less than 10 millions rows > 4) the index is a btree > > i tried to disable seq_scan and the query plan was changed and used another > index and not the one i wanted. You has ">" check on both columns, this means that it has to scan each subtree that satisfy one criteria to check against the other. Here index column order is significant. E.g. if you have a lot of xid > 100 and xid is first index column, it must check all (a lot) the index subtrees for xid>100. Multicolumn indexes work best when first columns are checked with "=" and only last column with range criteria. You may still try to change order of columns in your index if this will give best selectivity on first column. Another option is multiple single column indexes - postgres may merge such an indexes at runtime (don't remember since which version this feature is available). Best regards, Vitalii Tymchyshyn.