Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f8vLu-00078r-BV for pgsql-performance@arkaria.postgresql.org; Wed, 18 Apr 2018 22:14:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f8vLt-0002wu-6i for pgsql-performance@arkaria.postgresql.org; Wed, 18 Apr 2018 22:14:57 +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 1f8vLr-0002dK-Ne for pgsql-performance@lists.postgresql.org; Wed, 18 Apr 2018 22:14:55 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f8vLn-0003bP-Lu for pgsql-performance@lists.postgresql.org; Wed, 18 Apr 2018 22:14:54 +0000 Received: by mail-lf0-x241.google.com with SMTP id d79-v6so4899374lfd.0 for ; Wed, 18 Apr 2018 15:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=POq49leKN939rRh6HzQdrqADgMeJyxFH7RI/WaNelpM=; b=Vzy9rJknWFp0LJnofNhxGeXvYn2qWaPrwqNQF7yKOfE46IhoMRdA60Nzf1S7xKjQRY 7n9RaiXiB7tjGmedao+M0ELeZXi814zmIi/1C8VgOUd3pDyn719Q3tqzdrwXsQI9NO/a TNG5zdRUe7x/XXr5j/seVsIptxhUxLAGWRFh4JMxZUvs2eAW1Bh55JMp6NGLEDGqYuQR cZmttX5XcfHTJfC6J23LxeMWv2IvDNNyCyN19lev0xiwpoirxAFKPsi3bo/CCIprjN8q OK0q5h8YXKscO2f034im22C1FUMh8gmmCPP5FkrOjerQHpQRzBoOtnrILs9O2B8wmGtm wGng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=POq49leKN939rRh6HzQdrqADgMeJyxFH7RI/WaNelpM=; b=rZr5ks/BbzlPTedVkgvYhmNt724DMfVl0S7ebo52He3jDQPfeOo+s2GGeJaUP2v1D6 zFAWuPBoezuMORjx2aP3mN3JZpyTMs/XbQ+PyKOxk4GyN6Yxn2bnrFbEvvXh2NTg6ymb XLTNEZop9yilg0an8lv6L7ru6471v+XZY5Y1dKpr/+khvURQ3kITnLA5I6f0LRDGJJkt iyJeQY2RcDGBGRaM8LW14whYEm6fmyoP+qsiPo98t1XREEfS11gG6/XhXwLhLQKOaqGq Knh9jJePwzNpA+3n4+ocXN56tHZk275pNCDvlFuwD5MSs3w/KuUyU1m6rapIx1GLtfEM tyrw== X-Gm-Message-State: ALQs6tDy4BFgIcTJWTXR1RQU2TU/shuQk6kFAAB7CSGiRHzjRYDIgVi8 5CWitzAyfNP2rWY9jKpM0gUG/AF0 X-Google-Smtp-Source: AIpwx4+gAnl3xCOitRBAwjoQZnLnq8QXL8/GBBhk6s3FJrQVvWyLqz8NN/6k2F6tM3AY0Itui9W3vg== X-Received: by 10.46.156.68 with SMTP id t4mr2582690ljj.86.1524089689125; Wed, 18 Apr 2018 15:14:49 -0700 (PDT) Received: from [192.168.1.151] ([178.54.41.83]) by smtp.gmail.com with ESMTPSA id u64sm346441lja.74.2018.04.18.15.14.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Apr 2018 15:14:48 -0700 (PDT) To: "pgsql-performance@lists.postgresql.org" From: Vitaliy Garnashevich Subject: SeqScan vs. IndexScan Message-ID: <439201cf-0a22-8b48-34bd-f311108acd0f@gmail.com> Date: Thu, 19 Apr 2018 01:14:48 +0300 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 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 Hi, I'm running the same query with "set enable_seqscan = on;" and "set enable_seqscan = off;": ->  Nested Loop Left Join  (cost=0.00..89642.86 rows=1 width=30) (actual time=1.612..6924.232 rows=3289 loops=1)       Join Filter: (sys_user.user_id = j_6634.id)       Rows Removed by Join Filter: 14330174       ->  Seq Scan on sys_user  (cost=0.00..89449.85 rows=1 width=16) (actual time=0.117..39.802 rows=3289 loops=1)             Filter: ...       ->  Seq Scan on cmn_user j_6634  (cost=0.00..138.56 rows=4356 width=22) (actual time=0.001..0.973 rows=4358 loops=3289) (Full plan: https://explain.depesz.com/s/plAO) ->  Nested Loop Left Join  (cost=0.56..89643.52 rows=1 width=30) (actual time=0.589..39.674 rows=3288 loops=1)       ->  Index Scan using sys_user_pkey on sys_user (cost=0.28..89635.21 rows=1 width=16) (actual time=0.542..29.435 rows=3288 loops=1)             Filter: ...       ->  Index Scan using cmn_user_pkey on cmn_user j_6634 (cost=0.28..8.30 rows=1 width=22) (actual time=0.002..0.002 rows=1 loops=3288)             Index Cond: (sys_user.user_id = id) (Full plan: https://explain.depesz.com/s/4QXy) Why optimizer is choosing SeqScan (on cmn_user) in the first query, instead of an IndexScan, despite of SeqScan being more costly? Regards, Vitaliy