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 1fQGdk-0005Lu-15 for pgsql-general@arkaria.postgresql.org; Tue, 05 Jun 2018 18:25:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fQGdi-0002Se-NH for pgsql-general@arkaria.postgresql.org; Tue, 05 Jun 2018 18:25:02 +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 1fQGdi-0002SV-DT for pgsql-general@lists.postgresql.org; Tue, 05 Jun 2018 18:25:02 +0000 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fQGdf-0006tI-Cb for pgsql-general@lists.postgresql.org; Tue, 05 Jun 2018 18:25:01 +0000 Received: by mail-io0-x243.google.com with SMTP id r24-v6so4509467ioh.9 for ; Tue, 05 Jun 2018 11:24:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=MIVm1rUh0h0dbF+9udbxKpvAsVyfdQR7ssXv1h50MYs=; b=YddJi1A/yaIl4OoNlULZvhTSa4SYGySDPiO88XNqmZvdQChcHJbdiZ0I7hU+gHgXCW JmJhZJ2tg8j8mt8V/YDKaEPv9H37hInNsizqi2Gl0U34LLb+L8VWIiNujGsoEhOfBUHX S2FRiLhDiX8LzyjvoCgEbgS/E3HIVkMOOsmsaaewbTKVmhSq71dS7wYKjRjNwwqndkPd U7J19mdrx30G6BSB/d+zyEO7F9/bhQYQrXitVf5QfAylt4DJaSJpQpVuCBp6rKZrHj7/ 9S9B1x95Vpv9qa24hSyEgM+SxhmfjLIG/qa0gq+19nPS1eUvqhqDLyngZaC2QRa6dRY2 fXVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=MIVm1rUh0h0dbF+9udbxKpvAsVyfdQR7ssXv1h50MYs=; b=qdkaYCXo9CbsyxjVPHT3JV/pehy8SY5Wm+UPJNTCU18iqgT3xrrJrsQzzJ262E9795 XIDoKjF+BDGJWQHIg6v+1hd0a2U2XgZq3yx8q/rhy3bpTOEVF0YvMAhgnkR3EsfUYHSm 9wpljzkrVZJUdK6cj+vJNOdTT0aXUompaXwStWhh3DQjHidw0/srnONZDejnX43Wp6fz MvmHqbtvxDFDNh9UtjUufuLPPHd1gj+fGD4IiXShWGtGfzqfL9GVP6CMSneaPCZ0QWQF SjyxWmoA2s+43Bsky1gU2SEY9UOyzDch0ejRXRzCOudVgV+RCu9P6vNa3CN1qcDi7cNy OSNA== X-Gm-Message-State: ALKqPwdVp03vQ/bfUa5LYnZLaAvhvH6kQZpTOcy7QXrxlQqoVPh8Jrw+ Y97PWnIKzdUBGrMwAduYhqWhhaLb X-Google-Smtp-Source: ADUXVKKPJhYBLsuK4aeSiIpPyGhO4JYVcvpMypsIIaB+nTwTVGpUo8PK5cOELBNs4rZJEHVylte8KQ== X-Received: by 2002:a6b:2401:: with SMTP id k1-v6mr21990144iok.270.1528223097528; Tue, 05 Jun 2018 11:24:57 -0700 (PDT) Received: from ?IPv6:2605:a601:2062:d00:dc9c:bd1c:7370:376a? ([2605:a601:2062:d00:dc9c:bd1c:7370:376a]) by smtp.gmail.com with ESMTPSA id a23-v6sm5637596ioc.81.2018.06.05.11.24.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jun 2018 11:24:56 -0700 (PDT) From: armand pirvu Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: limit and query planner Message-Id: <59ED87E7-B582-481A-9FD8-CB77C7A3B268@gmail.com> Date: Tue, 5 Jun 2018 13:24:25 -0500 To: "pgsql-generallists.postgresql.org" X-Mailer: Apple Mail (2.3273) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk All Please see below explain analyze select * from sp_i2birst_reg_staging_test where evt_id =3D= 'ACSF17' =20 and status=3D0 limit 10; QUERY PLAN = =20 = --------------------------------------------------------------------------= --------------------------------------------------------- Limit (cost=3D0.00..1.29 rows=3D10 width=3D519) (actual = time=3D0.110..0.439 rows=3D10 loops=3D1) -> Seq Scan on sp_i2birst_reg_staging_test (cost=3D0.00..548.40 = rows=3D4239 width=3D519) (actual time=3D0.109..0.429 rows=3D10 loops=3D1) Filter: (((evt_id)::text =3D 'ACSF17'::text) AND (status =3D = 0)) Rows Removed by Filter: 115 Planning time: 3.022 ms Execution time: 0.639 ms (6 rows) birstdb=3D# \d sp_i2birst_reg_staging_test Table = "csischema.sp_i2birst_reg_staging_test" Column | Type | = Modifiers =20 = ---------------+-----------------------------+----------------------------= --------------------------------------------- action_id | bigint | not null default = nextval('i2birst_reg_staging_action_id_seq'::regclass) reg_uid | integer | not null evt_uid | integer | not null evt_id | character varying(10) | not null operation | character varying(6) | not null status | smallint | not null category | character varying(20) | not null default = ''::character varying add_date | timestamp with time zone | not null default now() mod_date | timestamp with time zone | not null default now() ingres_data | jsonb |=20 thread_number | bigint | not null default 0 start_time | timestamp without time zone |=20 end_time | timestamp without time zone |=20 Indexes: "sp_i2birst_reg_staging_test_pkey" PRIMARY KEY, btree (action_id) "sp_i2birst_reg_staging_test_idx" btree (status, evt_id, category) Check constraints: "sp_i2birst_reg_staging_test_status_check" CHECK (status =3D ANY = (ARRAY[0, 1, 2, 3])) Even if add an index on evt_id and status same table scan But=20 select count(*) from sp_i2birst_reg_staging_test; count=20 ------- 6860 select count(*) from sp_i2birst_reg_staging_test where evt_id =3D = 'ACSF17' =20 and status=3D0 ; count=20 ------- 4239 So I can see why the planner is choosing a table scan=20 My question is: I suspect the limit simply limits the fethching to the = first n-records retrieved and has no implications whatsoever on the = planner, meaning the planner ignores it. Am I right or wrong ? Thanks =E2=80=94 Armand