Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv6Me-0002Ps-W0 for pgsql-performance@arkaria.postgresql.org; Thu, 21 Sep 2017 18:38:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dv6Me-0006mW-CW for pgsql-performance@arkaria.postgresql.org; Thu, 21 Sep 2017 18:38:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dv6Md-0006lh-E7 for pgsql-performance@postgresql.org; Thu, 21 Sep 2017 18:38:19 +0000 Received: from mail-wr0-x231.google.com ([2a00:1450:400c:c0c::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dv6Ma-0001uy-Vk for pgsql-performance@postgresql.org; Thu, 21 Sep 2017 18:38:18 +0000 Received: by mail-wr0-x231.google.com with SMTP id k20so5253073wre.4 for ; Thu, 21 Sep 2017 11:38:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=CmkIY2vs6DsQMEx+wy+txEIHnqRavF4GDVqV8CO/eUU=; b=jnGOjLYpSif44SO9vnsT8zmzLBZ6PldoBxBti1Ig2Kij7Gvr0afzJyeFvFD9DbURJh 7SUc6PminfZqY5EKQeOaWNzKG3Ir1oamCfPWJ7/MD4cAMgkZI7JQzm3Jcw8IxNtTyrQa Cgsv+advufovHwxd/1nDorQRPm2egqjjHqiCqHLAmVlmspLFM5O4VsHfNqClNXK7rdak 9wwiFrJK9zrRpB40fJ/BX44LGOzfGy6VvWOgdkVkQJIK8tDaqZrB4K4nv/2L8S6cuzUB zkpA8/wrKaFSA30EKcdfaUy5Ig9m9knwUTsK1p+jXhRX5z2OhwlCAYoOQ1Z7Dkjb6OS3 EzPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=CmkIY2vs6DsQMEx+wy+txEIHnqRavF4GDVqV8CO/eUU=; b=ZlVefAjuh4zx6A/zLsWaI0KiEwqUDUP7eZkmxlmtdbtToOTR0zSenPIg2v1DUTkrhH 214pY8+RnhZwlz96dy4P+CwJS31VQj+2Tt8X6WDbSHh/rHaZzr41xKkcbcSdbyRGua9E YV0JTGpvjHG9PG9W902PGfw7zcrPO4RJqW3SdzmX+4CQKCALlENeqboLG5oms+MU0INw SSlA6o58ZV45Q7Msv+q8cFg8ucnZq1qYsSzUBegT/p3JM/epxaOiwtmwNIfUiQ2+Hxt9 wWContanPgd9GjMaPvwJZJu2EdjIaVHvHS8a1m0Y/0xJAIxXuGZR2XzwDaiutaIKKkLL gZXw== X-Gm-Message-State: AHPjjUiSCsvzzleuHUj2mW5ztKoXsHWcExvgpYujGOhYJwAyzN4dELm5 xKri+5pzeSw0uKRCY6govkfKZXdUWW5obNAEpP4= X-Google-Smtp-Source: AOwi7QANuxGG1fTsDBwXgnTPoH+SiDLSJbM80O9Rhc9ZQs4Nsyj/PvdOUFyB+C2tvj+RfmFDpTdypxzlMRypPNoMXLg= X-Received: by 10.223.183.27 with SMTP id l27mr2616512wre.138.1506019095033; Thu, 21 Sep 2017 11:38:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.173.176 with HTTP; Thu, 21 Sep 2017 11:37:34 -0700 (PDT) In-Reply-To: References: From: Pavel Stehule Date: Thu, 21 Sep 2017 20:37:34 +0200 Message-ID: Subject: Re: Query regarding EXPLAIN (ANALYZE,BUFFERS) To: Subramaniam C Cc: "pgsql-performance@postgresql.org" Content-Type: multipart/alternative; boundary="f403043891082f3aa10559b76597" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org --f403043891082f3aa10559b76597 Content-Type: text/plain; charset="UTF-8" 2017-09-21 12:52 GMT+02:00 Subramaniam C : > Hi > > I wanted to query top 20 rows by joining two tables, one table having > around 1 lac rows and other table having 5 lac rows. Since I am using ORDER > BY in the query so I created compound index with the columns being used in > ORDER BY. Initially index size was 939 MB. > > Then I ran EXPLAIN(ANALYZE,BUFFERS) for this query which took around 20 > secs as it was not using the compound index for this query. So I drop this > index and created again. The index size now got reduced to 559 MB. > > After this if I ran the EXPLAIN(ANALYZE,BUFFERS) for this query it was > using the index and took only 5 secs. > > Can you please explain how the index size got reduced after recreating it > and how the query started using the index after recreating? > > The index can be bloated - when you recreate it or when you use REINDEX command, then you remove a bloat content. VACUUM FULL recreate indexes too. Fresh index needs less space on disc (the read is faster), in memory too and has better structure - a access should be faster. > Thanks and Regards > Subramaniam > --f403043891082f3aa10559b76597 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


2017-09-21 12:52 GMT+02:00 Subramaniam C <subramaniam31784@g= mail.com>:
Hi

I wanted to query top 20 rows by joining two tables, one table h= aving around 1 lac rows and other table having 5 lac rows. Since I am using= ORDER BY in the query so I created compound index with the columns being u= sed in ORDER BY. Initially index size was =C2=A0939 MB.

Then I ran E= XPLAIN(ANALYZE,BUFFERS) for this query which took around 20 secs as it was = not using the compound index for this query. So I drop this index and creat= ed again. The index size now got reduced to 559 MB.

After this if I = ran the EXPLAIN(ANALYZE,BUFFERS) for this query it was using the index and = took only 5 secs.

Can you please explain how the index size got redu= ced after recreating it and how the query started using the index after rec= reating?


The index= can be bloated - when you recreate it or when you use REINDEX command, the= n you remove a bloat content. VACUUM FULL recreate indexes too.

Fresh index needs less space on disc (the read is faster)= , in memory too and has better structure - a access should be faster.
<= /div>

=C2=A0
Thanks and Regards
Subramaniam

--f403043891082f3aa10559b76597--