Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dwZ1x-0004sz-4G for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Sep 2017 19:27:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dwZ1w-0000t7-Ik for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Sep 2017 19:27:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dwZ1w-0000sy-6q for pgsql-bugs@postgresql.org; Mon, 25 Sep 2017 19:27:00 +0000 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dwZ1s-0005Xn-AQ for pgsql-bugs@postgresql.org; Mon, 25 Sep 2017 19:26:59 +0000 Received: by mail-wr0-x22a.google.com with SMTP id a43so9670881wrc.0 for ; Mon, 25 Sep 2017 12:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=dlo3HFzn8hayX4iqXgVu6s7JZ89BHN4MhO5g/FwvlKI=; b=jxhGBqQwV76oI43xmwmSAaHCV6AsoKG5NboHDlOfpdbbxu61t2WmngcaW1Av3gydAy TPbfwsbDVoX9212aNd6RCw6mnpra7s9ND0/ccPMu2s2en2YLMEmcRHbotyrm1D0pHuoq 3Zn4jLhKW0SMWs7ExCTgsdjFdM7igc6Cars2vbLuDaTWEgEImqD+mmoadTz56IZA3xya 2QgMkdwfgwmoptDT2xzhgdxd5FjNW+moS0MeouSN55Bf0cGkpZ1YY5O+eE8brIoSQQFr fMzMM+e+K4J7G7JpVfDcT6J31+KFyjkioDOiBlT7ZDyj4Pp87evt8p5OK2OqUO6stTig BXdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=dlo3HFzn8hayX4iqXgVu6s7JZ89BHN4MhO5g/FwvlKI=; b=BJCyrGV4gVMul5li87n2xQyMIzpERHYxNM1jrKTYWaYmGHcvkfmgvzQZL/rq8OX82C G71gTZYRrE5SmesY1wg167ruybN99/jAOrfGCTDF+lX/4b44+JaptYM5xxC2h3gSU3wf BU5eV6QzQ+/N1qe+Px3Ef98EOdVV1KRIyh6Lnqy2Su7MgIJKh86XHLtV6WhbfakuZ/eT gtQ0fRaLHesDLn5+OPsE9u+4Wyp4eC8hDoxE18QvdvDbCEUF9huzdtxJv19VVKJGVd+S 7wftUxlz8IyPhRf+XimCyQVHxv10Pgn5hwYMkstNK8JoHTlE5nxi8kQ0rZVsMn/uRLQ5 2jDQ== X-Gm-Message-State: AHPjjUgv+bC5Fd9oi7lxVI/LWuN04VKwO6Et8ix1EZi0rfdrm4pdY2aJ SHSn3G0DWaPVzv4f9/z1EaP86sV3+rOUe9knKMh6L7TC9VM8MDO2c8wy/EywVAaVXZhIOc0hyzZ rdUY6YDVnX13d/4w2XdWzCbtgyy3DDPJyJyAtOrfyjFuUNFHcs5hy7GUi+O0ikirttFxVDiCMEU zZzANV X-Google-Smtp-Source: AOwi7QCAqXNgwKySAXg1UPQqQTfOcTsjFBbKDLEnr/kq/q47NB2K9An+K4b3s6noEFBqA89wwrCOCQ== X-Received: by 10.223.176.132 with SMTP id i4mr6747393wra.13.1506367614869; Mon, 25 Sep 2017 12:26:54 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id a195sm141219wme.34.2017.09.25.12.26.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Sep 2017 12:26:54 -0700 (PDT) Subject: Re: Query planner skipping index depending on DISTINCT parameter order (2) To: =?UTF-8?B?0JTQuNC70Y/QvSDQn9Cw0LvQsNGD0LfQvtCy?= , Greg Stark , Tom Lane Cc: PostgreSQL Bugs References: <3c651d99-a943-4e21-4ec9-604b142c85e0@aegee.org> <57ccc03b-279a-63f7-19c6-6fe3b2d0e1be@aegee.org> <271e4961-abfa-06ef-a502-cf00a31b236a@2ndquadrant.com> <12044.1505668534@sss.pgh.pa.us> <6e8b3a9b-9b3d-e655-4456-f91a1ea3292b@aegee.org> From: Tomas Vondra Message-ID: <200285f5-801c-a53d-3a7d-9828d06947f0@2ndquadrant.com> Date: Mon, 25 Sep 2017 21:26:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <6e8b3a9b-9b3d-e655-4456-f91a1ea3292b@aegee.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 09/25/2017 08:10 PM, Дилян Палаузов wrote: > Hello, > > for the record, in this table > > spamassassin=> \d bayes_token >            Table "public.bayes_token" >   Column    Type            Modifiers > ────────── ─────── ──────────────────────────── > id         integer not null default 0 > token      bytea   not null default '\x'::bytea > spam_count integer not null default 0 > ham_count  integer not null default 0 > atime      integer not null default 0 > Indexes: >     "bayes_token_pkey" PRIMARY KEY, btree (id, token) >     "bayes_token_idx1" btree (token) > > > "SELECT id, token FROM bayes_token" and "SELECT id, token FROM > bayes_token WHERE id > 0" do Seq Scan and need 35-50 Sec. > > But "SELECT id, token FROM bayes_token WHERE id > 1" uses Index Only > Scan and 0.04 seconds on pg 9.6.5 . > I don't quite see how this is related to the original topic in this thread, which was discussing DISTINCT ON vs. indexes. But more importantly, it's really difficult to give you answers without you showing us EXPLAIN (and ideally EXPLAIN ANALYZE) for the queries. FWIW, my guess is that there are many rows with (id > 0), and scanning them using index only scan would be expensive. While there are only very few rows with (id > 1), so the database uses IOS. You can try pushing the database towards IOS by disabling sequential and bitmap scans. set enable_seqscan = off; set enable_bitmapscan = off; regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs