Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hH1G2-0001tU-98 for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2019 07:14:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hH1G0-00056W-Ri for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2019 07:14:52 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hH1G0-00056O-IK for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2019 07:14:52 +0000 Received: from mail.i-mark.de ([188.138.104.222]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hH1Fy-00038I-43 for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2019 07:14:52 +0000 Received: from [192.168.178.20] (unknown [185.38.49.7]) by mail.i-mark.de (Postfix) with ESMTPSA id B4C8E158040F for ; Thu, 18 Apr 2019 09:14:46 +0200 (CEST) Authentication-Results: loft7616.startdedicated.de; spf=pass (sender IP is 185.38.49.7) smtp.mailfrom=andreas@a-kretschmer.de smtp.helo=[192.168.178.20] Received-SPF: pass (loft7616.startdedicated.de: connection is authenticated) Subject: Re: Multicolumn index for single-column queries? To: pgsql-general@lists.postgresql.org References: <95ade9a3-6846-3f55-f936-85b8bb4b46a8@mail.ru> From: Andreas Kretschmer Message-ID: Date: Thu, 18 Apr 2019 09:14:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <95ade9a3-6846-3f55-f936-85b8bb4b46a8@mail.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Am 18.04.19 um 08:52 schrieb rihad: > Hi. Say there are 2 indexes: > >     "foo_index" btree (foo_id) > >     "multi_index" btree (foo_id, approved, expires_at) > > > foo_id is an integer. Some queries involve all three columns in their > WHERE clauses, some involve only foo_id. > Would it be ok from general performance standpoint to remove foo_index > and rely only on multi_index? I know that > PG would have to do less work updating just one index compared to > updating them both, but wouldn't searches > on foo_id alone become slower? it depends . it depends on the queries you are using, on your workload. a multi-column-index will be large than an index over just one column, therefore you will have more disk-io when you read from such an index. Regards, Andreas -- 2ndQuadrant - The PostgreSQL Support Company. www.2ndQuadrant.com