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 1hH71d-0008RZ-HM for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2019 13:24:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hH71c-0002v8-2U for pgsql-general@arkaria.postgresql.org; Thu, 18 Apr 2019 13:24:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hH71b-0002lM-Cz for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2019 13:24:23 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hH71Y-0007NI-1k for pgsql-general@lists.postgresql.org; Thu, 18 Apr 2019 13:24:22 +0000 Received: by mail-oi1-x22b.google.com with SMTP id v10so1594228oib.1 for ; Thu, 18 Apr 2019 06:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=mdy3uZSInCKVAfUwKLyuZZfo0Mdnn6bY+doW5O9g/cM=; b=uYnwkf+4GdShDZzQ7bDuILvGBZF4vHql3dZujVm2rcIRd3hCBJfPzF6y/YlP68fJ+1 Zb+yTGxRhAiILyb8vk5cHufKrTq/P8aYO4U3PUhl6g6etDb6ITW7CBtAFZLQwKGlPnIH CLL3s+QM8apltzuOn38as8oMKyTW/+MyN/JViCGdRWJwAA9HMnpMQv2Cnb96Sto0WNTt qWz2K2/fzsbx+41bUiQz3h9j6eiibtC2rn66J0EvRgv8cc7fvEX2/oyTlOCSbKhdC4dL 59KVcnMvfVfgyZRiA/eOW7zQTpLgVUavVF8v3N/mE7E2MjxBTYOTVnYhQtGi6yJUsUjf vGiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=mdy3uZSInCKVAfUwKLyuZZfo0Mdnn6bY+doW5O9g/cM=; b=uQMGhD909Is3P8fwW726f4bTi7Fcccyi3veNfsLabTTlquZ16tKwgr4fhTVHoyOoCU hhhYxFgehaCTAMK8FjK8scxCQbB1XhWLLe7kXpGUGylPvhNuK66nfDWbk9E9vROZobYL JcXa7a3iG9dB9vPkuGL/czlzobfv/N4qQXCYqzk6/WdmaeFuv6tp07pLkqQSAakG2Aah Lat6VrS8GiL8yVB35tlCUj522Jdd8qivRtlk+1cRzpUQkReGztcjkdNuYQH+t9I+BtnG 4DXqPS0v3TwiUcRLY3jqtV4c4fhJeBGbHjAsaQq/iO/eM8BhPJPfR8Yf20E6zu0R6FRz 6fkA== X-Gm-Message-State: APjAAAX58U7wDkrMaR3SyOlQi0H8ZV8dVf4FZdsl1i4OGB+ul24RpkyG c/gNYsQQPkB3jOF+vaVnU+nrCl8ESOQ= X-Google-Smtp-Source: APXvYqw5bqxcjglc8L1JPrDLBxt/GeWyOVGseh0k9r9HOfLrVPnpvVukCiUJRX0vFNTQdSoiMvqlLw== X-Received: by 2002:aca:4f56:: with SMTP id d83mr1804473oib.24.1555593858638; Thu, 18 Apr 2019 06:24:18 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id x89sm819961ota.30.2019.04.18.06.24.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 06:24:17 -0700 (PDT) Subject: Re: Multicolumn index for single-column queries? To: pgsql-general@lists.postgresql.org References: <95ade9a3-6846-3f55-f936-85b8bb4b46a8@mail.ru> From: Ron Message-ID: <59f265b2-192a-33cd-7b18-d93c068e83e3@gmail.com> Date: Thu, 18 Apr 2019 08:24:17 -0500 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: Content-Type: multipart/alternative; boundary="------------4167C91144C15D1E50101E2D" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------4167C91144C15D1E50101E2D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 4/18/19 2:14 AM, Andreas Kretschmer wrote: > > > 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. But two indexes are larger than one index, and updating two indexes requires more disk IO than updating one index. (Prefix compression would obviate the need for this question.  Then your multi-column index would be *much* smaller.) -- Angular momentum makes the world go 'round. --------------4167C91144C15D1E50101E2D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 4/18/19 2:14 AM, Andreas Kretschmer wrote:


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.

But two indexes are larger than one index, and updating two indexes requires more disk IO than updating one index.

(Prefix compression would obviate the need for this question.  Then your multi-column index would be much smaller.)


--
Angular momentum makes the world go 'round.
--------------4167C91144C15D1E50101E2D--