Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g4D4Q-0004Bk-JG for pgsql-general@arkaria.postgresql.org; Sun, 23 Sep 2018 22:41:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g4D4O-0002UO-TV for pgsql-general@arkaria.postgresql.org; Sun, 23 Sep 2018 22:41:40 +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.89) (envelope-from ) id 1g4D4O-0002UH-Jr for pgsql-general@lists.postgresql.org; Sun, 23 Sep 2018 22:41:40 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g4D4L-0006KD-Sv for pgsql-general@lists.postgresql.org; Sun, 23 Sep 2018 22:41:40 +0000 Received: by mail-wm1-x342.google.com with SMTP id l7-v6so3036249wme.2 for ; Sun, 23 Sep 2018 15:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=x/dSDRWFwD6Fk3ljAmlKStugnxJPgO6s1F773INGy7Y=; b=SGAvW9l4pln/KBqsaDAT+Dz08i1hsXlyQTcIl4r2AhMiNIGcxNCiofeO2f1CC02niy pLgpCVtRvi8rtQ0FUfbf/LCACPWeUDofDEvi1Uaqv/v25ZGPpkMThruMXT2R/xC6HWjr 1Mx+wNlLtyi59FrLtkMkAGByznH6GpbZD1Tlgvi3ydFM/cb6Sma5LIznzsRQcy+Se93v PQkf/ssqLxHzu+9eJTZY6oYir0WAyQrEwMwDuVoBRwtW4exIwa4GrQ1zoYKtBvPwudQR Qq3EciGi8nPCOIOiVj6H4lM2M0oA8Kzo3NXaD6T87BxDjP515FfkmNDcsibc5GvLnbSn 1wrA== 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 :content-transfer-encoding; bh=x/dSDRWFwD6Fk3ljAmlKStugnxJPgO6s1F773INGy7Y=; b=l/AQngXwBwgkFIH+NN3U+R96WEx/qoGtngTxh/ci/AskAGYhxsBzx3IuS4/JcfNEOp l8r289isHfdlGXKRnuOWPXXUV1INDBnz6HpFr5a2ABuW0aDMOByEcPKfHELCBDW5+2at upOBgi5ncz6PNxBU38zAQ10c//K2s442Z1c89rxtD03wgC9Io6TDUG5k+DQkxNcApCqm pfSKQLtiMnd+0Y/1iRHYZEHig6amPoOlwGeCzK85LtCUj/tkSWplaT4mzwwXS/NVAzDs cdIfMWhmAkQZmrR+ZaBZxhuDtB/CzlqZHctw6gIcoWNkqhEDk7vgzxKewqJTf3arbD1G FyGA== X-Gm-Message-State: APzg51DjlH+Bs8tEckGbU38TB1bRmQ+5IWMJdKaEZYvb5/MLgsoo2Bu1 YuBO0lyuULGwTyzucCj6dJWxpNF8uNpeGLuWN73Pmq90yiY6hktB5t/fUrrL+Msfs36XxTiaSqi XNVuBjwSr5U2kKT2bsYlQ5udZlZ3wdY/ZNj5RRD1lpYjsYXVinD6vXQ0g8OvvFvXY0hc4WxuLsZ CsMDScmq267tZaR1Yvl4Y= X-Google-Smtp-Source: ANB0VdZp6m14NDB++3F124UCzw6oA9ol8wZclrtRfSZ5Kkh8hZhxm5ElextLowMStwAfC7B6c89yFw== X-Received: by 2002:a1c:8f0e:: with SMTP id r14-v6mr4935121wmd.79.1537742495946; Sun, 23 Sep 2018 15:41:35 -0700 (PDT) Received: from [10.137.2.19] (ip-86-49-246-165.net.upcbroadband.cz. [86.49.246.165]) by smtp.gmail.com with ESMTPSA id 72-v6sm31400246wrb.48.2018.09.23.15.41.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Sep 2018 15:41:35 -0700 (PDT) Subject: Re: Help to understand Actual Rows vs Plan Rows from the query planner output To: pgsql-general@lists.postgresql.org References: From: Tomas Vondra Message-ID: <409f074d-56f5-3dbb-b4e1-6c0b69f27952@2ndquadrant.com> Date: Mon, 24 Sep 2018 00:41:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 09/23/2018 10:21 PM, Arup Rakshit wrote: > Hello I have some questions related to the query plan output about the > planned and actual rows. In the following example: > > # explain (analyze true, costs true, format yaml) select * from users > where lower(city) = 'melanyfort' and lower(state) = 'ohio'; >                                                  QUERY PLAN              >                                     > ------------------------------------------------------------------------------------------------------------ >  - Plan:                                                                 >                                   + >      Node Type: "Bitmap Heap Scan"                                       >                                   + >      Parallel Aware: false                                               >                                   + >      Relation Name: "users"                                              >                                   + >      Alias: "users"                                                      >                                   + >      Startup Cost: 10.78                                                 >                                   + >      Total Cost: 14.80                                                   >                                   + >      Plan Rows: 1                                                        >                                   + >      Plan Width: 73                                                      >                                   + >      Actual Startup Time: 0.155                                          >                                   + >      Actual Total Time: 0.155                                            >                                   + >      Actual Rows: 0                                                      >                                   + >      Actual Loops: 1                                                     >                                   + >      Recheck Cond: "((lower((city)::text) = 'melanyfort'::text) AND > (lower((state)::text) = 'ohio'::text))"+ >      Rows Removed by Index Recheck: 0                                    >                                   + >      Exact Heap Blocks: 0                                                >                                   + >      Lossy Heap Blocks: 0                                                >                                   + >      Plans:                                                              >                                   + >        - Node Type: "BitmapAnd"                                          >                                   + >          Parent Relationship: "Outer"                                    >                                   + >          Parallel Aware: false                                           >                                   + >          Startup Cost: 10.78                                             >                                   + >          Total Cost: 10.78                                               >                                   + >          Plan Rows: 1                                                    >                                   + >          Plan Width: 0                                                   >                                   + >          Actual Startup Time: 0.153                                      >                                   + >          Actual Total Time: 0.153                                        >                                   + >          Actual Rows: 0                                                  >                                   + >          Actual Loops: 1                                                 >                                   + >          Plans:                                                          >                                   + >            - Node Type: "Bitmap Index Scan"                              >                                   + >              Parent Relationship: "Member"                               >                                   + >              Parallel Aware: false                                       >                                   + >              Index Name: "users_lower_idx"                               >                                   + >              Startup Cost: 0.00                                          >                                   + >              Total Cost: 4.66                                            >                                   + >              Plan Rows: 50                                               >                                   + >              Plan Width: 0                                               >                                   + >              Actual Startup Time: 0.048                                  >                                   + >              Actual Total Time: 0.048                                    >                                   + >              Actual Rows: 1                                              >                                   + >              Actual Loops: 1                                             >                                   + >              Index Cond: "(lower((city)::text) = 'melanyfort'::text)"    >                                   + >            - Node Type: "Bitmap Index Scan"                              >                                   + >              Parent Relationship: "Member"                               >                                   + >              Parallel Aware: false                                       >                                   + >              Index Name: "lower_state_users_idx"                         >                                   + >              Startup Cost: 0.00                                          >                                   + >              Total Cost: 5.87                                            >                                   + >              Plan Rows: 211                                              >                                   + >              Plan Width: 0                                               >                                   + >              Actual Startup Time: 0.102                                  >                                   + >              Actual Total Time: 0.102                                    >                                   + >              Actual Rows: 211                                            >                                   + >              Actual Loops: 1                                             >                                   + >              Index Cond: "(lower((state)::text) = 'ohio'::text)"         >                                   + >    Planning Time: 0.260                                                  >                                   + >    Triggers:                                                             >                                   + >    Execution Time: 0.249 > (1 row) > > aruprakshit=#  > > > ------ > > In the first node type of "Bitmap Index Scan” on “users_lower_idx”, I > see the plan rows are 50, but actual rows it got 1. In the second node > type of "Bitmap Index Scan” on “ lower_state_users_idx”, I see the plan > rows are 211, and actual rows 211. Both are same. Based on what > conditions planner estimated the planned and actual rows count?  > > > In node type “BitmapAnd”, I see again the actual rows 1, then why on the > final plan i.e. Node Type: "Bitmap Heap Scan” again planner estimated > rows 1? How does it counts these? What does the Loops count says us > about the query?   > It's not very clear to me whether you're asking how the planner computes estimates in general, or how it computed these particular estimates (or what issues you see there). Perhaps this would give you at least some answers: https://www.postgresql.org/docs/11/static/row-estimation-examples.html regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services