Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lW4Ra-0007hq-AO for pgsql-general@arkaria.postgresql.org; Mon, 12 Apr 2021 21:50:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lW4RZ-0006d7-97 for pgsql-general@arkaria.postgresql.org; Mon, 12 Apr 2021 21:50:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lW4RY-0006d0-Qb for pgsql-general@lists.postgresql.org; Mon, 12 Apr 2021 21:50:05 +0000 Received: from sonic307-9.consmr.mail.ne1.yahoo.com ([66.163.190.32]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lW4RV-0004rK-OP for pgsql-general@postgresql.org; Mon, 12 Apr 2021 21:50:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1618264198; bh=weWrhMQPxPzfrw7SQaGWOfVOuSP+4pyQRJvyY8s0Vl0=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject:Reply-To; b=qqOpUcepFIpIAuO0UpBxwMUqUtsLaCt3ABd1+quRVycLnYMalFEKCjfQB56eUXoZi/QMxLaVKV8YP+X/4oOy0Czy7FxsWJIJ+sYcmwiyA9clklfxl4uRdrMRRHQ7rr1/9zCzQEHhwSkyOtSaamb3OEzFiKv82yqoKYoRs1hRl9SCJjvHaVHrOpB+amdYNQqVAeBfY8drHQkPSfMAGL6z4GBhqw1LTLcf4d8Bv2URNEv3ZQnI/BRCjVACO3vEQueQfITC/Vfw59tLjmDPkqlBw/n3H0UEMctk5xQguWsq7UUeqdd/xHTYetyOPq9hA9P0Asw4pmb3B491eYEDxOur3Q== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1618264198; bh=QQMxPf7rKn+ZUVtWxUL6aCq+vaouPsd212haM71p2rK=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=SdMAN3ACzXFr48AH29uFCaorysPx4u6Gn3BdjBqLfOeuooL887BJXmBCWmvLszfW3eE00xkql2O/ZCdFh84g/5sEpa+jKkHVFg7M7ZXX4MKwsWSO73NcoI0U7XHilZOUmK8aSKPXhWXX6ZhzF3J0SRTjxBzx7gBATy/44n1EzMQrSpfpqxucfk55+aj+IaOgCICOXxnjX+JeiPL0pjuHiYVIxXO1tl+xkzMhR9j2hCiamXSaZ6F8Fudh/Pyd7GWr/3i7OvgLWEyL+TVqh+Eo/lMhQ8P0OUOuDhrFCBhans77Yi1TM5fZK+9h32r5mBlvFWLQpYeGqeHKgU7r3ynATg== X-YMail-OSG: 6TRwWE4VM1lbaElckGlhY9osOLQl_GSl3qc3w71yKk3sklu6kCIUzLMWSkrwJky QaxZUoKSdhKcO8TUU6rfQhsOr.efwtKNRgOJ74x74gqfJXDkcgbTLje3u3neJqsPw2eqV.rOxO4y WbJAY05VnxpuwTHXhtQ82pgXNjGkXalzIm31qS58zaBPdmAsHZ5938ROdF3CeVimX9.4kqJ3woGk SpjO8rq36XL6aCxznNgRpwLe8m4rcXf.V37L7irs6umJdFvnGyr.vWotTAAixJjQ28zG9GZvUCiD lZHBPG4BFcV2QbFNoRuUUy21hw_ni5Fw3b0dg5I8TqwjTSwXDz_q5WKg9oHMNQbz1eu.RgCxgUFs fHu38a6muAf3PPK6ZaWwBfOXpWE3qy6gQ6EykHNNojDE4TANmRDMD4H3JHh5rsxTpMEtc4sOkcqh i.SNrqRKPya6dkFvrY_RAKgwni01dmvPeINSkh5YCKYRJo7Efk8yaj9nO2ksSaGrGDxqXQwDdSXF LHH0hK5KHScz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lUsFVM3VSR2Gw4UMNw7vB6UYtUQU8oQ1jn2bhoEj9CPrJpbA-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Mon, 12 Apr 2021 21:49:58 +0000 Date: Mon, 12 Apr 2021 21:49:55 +0000 (UTC) From: Virendra Kumar Reply-To: Virendra Kumar To: "pgsql-general@postgresql.org" , Vijaykumar Jain Message-ID: <1149545716.1330993.1618264195670@mail.yahoo.com> In-Reply-To: References: <602410180.890076.1618182864082.ref@mail.yahoo.com> <602410180.890076.1618182864082@mail.yahoo.com> Subject: Re: Prepare Statement VS Literal Values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Mailer: WebService/1.1.18121 YMailNorrin Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0 Content-Length: 27076 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thank you for the pointer, here is plan now, it is much better: testdb=3D# prepare fooplan(character varying,character varying ,bigint,char= acter varying) AS select testdb-# this_.warehouse_cost_id , this_.asin , this_.base_currency_code, testdb-# this_.cost , this_.cost_acquisition_date , this_.cost_reference_id= , testdb-# this_.cost_reference_id_source , this_.created_by , this_.creation= _date , testdb-# this_.gl_product_group , this_.warehouse_fiscal_owner_id , testdb-# this_.warehouse_owner_group_id , this_.warehouse_txn_type_id , testdb-# this_.item_disposition_code , this_.last_updated , this_.last_upda= ted_by , testdb-# this_.last_updated_date , this_.on_hand_quantity , this_.original_= quantity , testdb-# this_.record_version_number , this_.warehouse_id=C2=A0 from wareho= use_costs this_ testdb-# where this_.warehouse_id=3D$1 testdb-# and this_.asin=3D$2 testdb-# and this_.warehouse_owner_group_id=3D$3 testdb-# and this_.item_disposition_code=3D$4 testdb-# order by this_.cost_acquisition_date asc; PREPARE testdb=3D# explain (analyze, buffers) execute fooplan('IMXK','B002LA1D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2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------- =C2=A0Sort=C2=A0 (cost=3D8.46..8.47 rows=3D1 width=3D160) (actual time=3D0.= 108..0.110 rows=3D5 loops=3D1) =C2=A0=C2=A0 Sort Key: cost_acquisition_date =C2=A0=C2=A0 Sort Method: quicksort=C2=A0 Memory: 26kB =C2=A0=C2=A0 Buffers: shared hit=3D8 =C2=A0=C2=A0 ->=C2=A0 Index Scan using i_ic_asin_whse_disp_iog_qty on wareh= ouse_costs this_=C2=A0 (cost=3D0.42..8.45 rows=3D1 width=3D160) (actual tim= e=3D0.067..0.080 rows=3D5 loops=3D1) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Index Cond: ((asin =3D 'B0= 02LA1D9Y'::bpchar) AND (warehouse_id =3D 'IMXK'::bpchar) AND ((item_disposi= tion_code)::text =3D 'SELLABLE'::text) AND (warehouse_owner_group_id =3D '1= '::numeric)) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Buffers: shared hit=3D8 =C2=A0Execution time: 0.238 ms (8 rows) Regards, Virendra Kumar On Monday, April 12, 2021, 4:18:01 AM PDT, Vijaykumar Jain wrote:=20 I am sorry if i have messed up the email original content. feel free to ignore my diversion. i forwarded this mail from some other account to work on the issue. On Mon, Apr 12, 2021 at 4:45 PM Vijaykumar Jain wrote: >=20 > Hi, >=20 > I am not sure I am 100% on this, because=C2=A0I have a small machine at h= ome. >=20 > but reading=C2=A0PostgreSQL: Documentation: 9.6: PREPARE=C2=A0and > PostgreSQL - general - bpchar, text and indexes (postgresql-archive.org) >=20 > PostgreSQL: Documentation: 9.6: Operators >=20 > I think it might be something to do with the parameters types in the prep= ared=C2=A0statement and their casting. >=20 > But , the below would be reproducible >=20 > postgres=3D# create table t(t_id int4, sn_c char(20)); > CREATE TABLE > postgres=3D# insert into t select id, chr((random()*26)::int4+65)||chr((r= andom()*26)::int4+65)||((random()*99999)::int4+1) from generate_series(1, 1= 0000) id; > INSERT 0 10000 > postgres=3D# create index i_t_sn_c on t(sn_c); > CREATE INDEX > postgres=3D# vacuum analyze t; > VACUUM > postgres=3D# EXPLAIN (analyze, costs off) SELECT sn_c FROM t WHERE sn_c = =3D 'AB1234'; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QUERY PLAN > -------------------------------------------------------------------------= ------ > =C2=A0Index Only Scan using i_t_sn_c on t (actual time=3D0.048..0.048 row= s=3D0 loops=3D1) > =C2=A0 =C2=A0Index Cond: (sn_c =3D 'AB1234'::bpchar) > =C2=A0 =C2=A0Heap Fetches: 0 > =C2=A0Planning Time: 0.119 ms > =C2=A0Execution Time: 0.059 ms > (5 rows) >=20 > postgres=3D#=C2=A0 EXPLAIN (analyze, costs off) SELECT sn_c FROM t WHERE = sn_c =3D 'AB1234'::text; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0QUERY PLAN > --------------------------------------------------------- > =C2=A0Seq Scan on t (actual time=3D3.037..3.037 rows=3D0 loops=3D1) > =C2=A0 =C2=A0Filter: ((sn_c)::text =3D 'AB1234'::text) > =C2=A0 =C2=A0Rows Removed by Filter: 10000 > =C2=A0Planning Time: 0.057 ms > =C2=A0Execution Time: 3.047 ms > (5 rows) >=20 > postgres=3D# prepare qq(text) as SELECT sn_c FROM t WHERE sn_c =3D $1;=C2= =A0 // verify from select * from pg_prepared_statements. > PREPARE > postgres=3D# explain analyze execute qq('AB1234'); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Q= UERY PLAN > -------------------------------------------------------------------------= ---------------------- > =C2=A0Seq Scan on t=C2=A0 (cost=3D0.00..224.00 rows=3D50 width=3D21) (act= ual time=3D3.156..3.157 rows=3D0 loops=3D1) > =C2=A0 =C2=A0Filter: ((sn_c)::text =3D 'AB1234'::text) > =C2=A0 =C2=A0Rows Removed by Filter: 10000 > =C2=A0Planning Time: 0.069 ms > =C2=A0Execution Time: 3.168 ms > (5 rows) >=20 > postgres=3D# prepare qq(text) ^C SELECT sn_c FROM t WHERE sn_c =3D $1;=C2= =A0 // verify from select * from pg_prepared_statements. > postgres=3D# deallocate qq; > DEALLOCATE > postgres=3D# prepare qq(bpchar) as SELECT sn_c FROM t WHERE sn_c =3D $1; > PREPARE > postgres=3D# explain analyze execute qq('AB1234'); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QUERY PLAN > -------------------------------------------------------------------------= ----------------------------------------- > =C2=A0Index Only Scan using i_t_sn_c on t=C2=A0 (cost=3D0.29..4.30 rows= =3D1 width=3D21) (actual time=3D0.015..0.015 rows=3D0 loops=3D1) > =C2=A0 =C2=A0Index Cond: (sn_c =3D 'AB1234'::bpchar) > =C2=A0 =C2=A0Heap Fetches: 0 > =C2=A0Planning Time: 0.090 ms > =C2=A0Execution Time: 0.027 ms > (5 rows) >=20 > postgres=3D# \d t > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Tab= le "public.t" > =C2=A0Column |=C2=A0 =C2=A0 =C2=A0Type=C2=A0 =C2=A0 =C2=A0 | Collation | = Nullable | Default > --------+---------------+-----------+----------+--------- > =C2=A0t_id=C2=A0 =C2=A0| integer=C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | > =C2=A0sn_c=C2=A0 =C2=A0| character(20) |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | > Indexes: > =C2=A0 =C2=A0 "i_t_sn_c" btree (sn_c) >=20 > postgres=3D# deallocate qq; > DEALLOCATE > postgres=3D# prepare qq(bpchar) as SELECT sn_c FROM t WHERE sn_c =3D $1; > PREPARE > postgres=3D# explain analyze execute qq('AB1234'); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QUERY PLAN > -------------------------------------------------------------------------= ----------------------------------------- > =C2=A0Index Only Scan using i_t_sn_c on t=C2=A0 (cost=3D0.29..4.30 rows= =3D1 width=3D21) (actual time=3D0.015..0.015 rows=3D0 loops=3D1) > =C2=A0 =C2=A0Index Cond: (sn_c =3D 'AB1234'::bpchar) > =C2=A0 =C2=A0Heap Fetches: 0 > =C2=A0Planning Time: 0.074 ms > =C2=A0Execution Time: 0.027 ms > (5 rows) >=20 > postgres=3D# deallocate qq; > DEALLOCATE > postgres=3D# prepare qq(text) as SELECT sn_c FROM t WHERE sn_c =3D $1; > PREPARE > postgres=3D# explain analyze execute qq('AB1234'); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Q= UERY PLAN > -------------------------------------------------------------------------= ---------------------- > =C2=A0Seq Scan on t=C2=A0 (cost=3D0.00..224.00 rows=3D50 width=3D21) (act= ual time=3D3.129..3.130 rows=3D0 loops=3D1) > =C2=A0 =C2=A0Filter: ((sn_c)::text =3D 'AB1234'::text) > =C2=A0 =C2=A0Rows Removed by Filter: 10000 > =C2=A0Planning Time: 0.071 ms > =C2=A0Execution Time: 3.141 ms > (5 rows) >=20 >=20 > ---------- Forwarded message --------- > From: Virendra Kumar > Date: Mon, 12 Apr 2021 at 4:44 AM > Subject: Prepare Statement VS Literal Values > To: Pgsql-general General >=20 >=20 > Hi Team, >=20 > I am struggling a lot on this for at least 3-4 queries. When I run explai= n analyze using literal values the query takes good plan but as soon as I u= se bind variable using the prepare statement it is going for toss and the s= ame query is taking a lot of time. >=20 >=20 > testdb=3D# select version(); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 version=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 > -------------------------------------------------------------------------= -------------------------------------------- > =C2=A0PostgreSQL 9.6.11 on x86_64-apple-darwin19.6.0, compiled by Apple c= lang version 12.0.0 (clang-1200.0.32.29), 64-bit > (1 row) >=20 > testdb=3D# \d+ warehouse_costs > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 Table "public.warehouse_costs" > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Column=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Type=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | Modifiers= | Storage=C2=A0 | Stats target | Description > ---------------------------+--------------------------------+-----------+= ----------+--------------+------------- > =C2=A0warehouse_cost_id=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= numeric(38,0)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2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2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | extended |=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | > =C2=A0gl_product_group=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 | numeric(4,0)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | main=C2=A0=C2=A0=C2=A0=C2=A0 |=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= | > =C2=A0base_currency_code=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | char= acter varying(15)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | extended |= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 | > =C2=A0cost_acquisition_date=C2=A0=C2=A0=C2=A0=C2=A0 | timestamp(0) withou= t time zone |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= plain=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |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C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 | > =C2=A0creation_date=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 | timestamp(0) without time zone |=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | plain=C2=A0=C2=A0=C2=A0 |=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | > =C2=A0created_by=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | character varying(8)=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | extended |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | > =C2=A0last_updated_date=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= timestamp(0) without time zone |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 | plain=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | > =C2=A0last_updated_by=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 | character varying(8)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 | extended |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 | > =C2=A0last_updated=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 | timestamp(0) without time zone |=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | plain=C2=A0=C2=A0=C2=A0 |= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 | > =C2=A0record_version_number=C2=A0=C2=A0=C2=A0=C2=A0 | numeric(38,0)=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 | main=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | > =C2=A0warehouse_owner_group_id=C2=A0 | numeric(38,0)=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | main= =C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | > =C2=A0warehouse_fiscal_owner_id | numeric(38,0)=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | main=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 | > Indexes: > =C2=A0=C2=A0=C2=A0 "pk_inventory_costs" PRIMARY KEY, btree (warehouse_cos= t_id) > =C2=A0=C2=A0=C2=A0 "i_ic_asin_whse_disp_iog_qty" btree (asin, warehouse_i= d, item_disposition_code, warehouse_owner_group_id, on_hand_quantity) > =C2=A0=C2=A0=C2=A0 "i_ic_cost_date_asin_iog_id" btree (cost_acquisition_d= ate, asin, warehouse_owner_group_id) > =C2=A0=C2=A0=C2=A0 "i_ic_inventory_txn_type_id" btree (warehouse_txn_type= _id) > =C2=A0=C2=A0=C2=A0 "i_ic_last_updated" btree (last_updated) >=20 > testdb=3D# prepare fooplan(text,text,bigint,text) AS select > testdb-# this_.warehouse_cost_id , this_.asin , this_.base_currency_code, > testdb-# this_.cost , this_.cost_acquisition_date , this_.cost_reference_= id , > testdb-# this_.cost_reference_id_source , this_.created_by , this_.creati= on_date , > testdb-# this_.gl_product_group , this_.warehouse_fiscal_owner_id , > testdb-# this_.warehouse_owner_group_id , this_.warehouse_txn_type_id , > testdb-# this_.item_disposition_code , this_.last_updated , this_.last_up= dated_by , > testdb-# this_.last_updated_date , this_.on_hand_quantity , this_.origina= l_quantity , > testdb-# this_.record_version_number , this_.warehouse_id=C2=A0 from ware= house_costs this_ > testdb-# where this_.warehouse_id=3D$1 > testdb-# and this_.asin=3D$2 > testdb-# and this_.warehouse_owner_group_id=3D$3 > testdb-# and this_.item_disposition_code=3D$4 > testdb-# order by this_.cost_acquisition_date asc; > ERROR:=C2=A0 prepared statement "fooplan" already exists > Time: 0.645 ms > testdb=3D# > testdb=3D# explain (analyze, buffers) execute fooplan('IMXK','B002LA1D9Y'= ,'1','SELLABLE'); >=20 > explain analyze > select > this_.warehouse_cost_id , this_.asin , this_.base_currency_code , > this_.cost , this_.cost_acquisition_date , this_.cost_reference_id , > this_.cost_reference_id_source , this_.created_by , this_.creation_date , > this_.gl_product_group , this_.warehouse_fiscal_owner_id , > this_.warehouse_owner_group_id , this_.warehouse_txn_type_id , > this_.item_disposition_code , this_.last_updated , this_.last_updated_by = , > this_.last_updated_date , this_.on_hand_quantity , this_.original_quantit= y , > this_.record_version_number , this_.warehouse_id=C2=A0 from warehouse_cos= ts this_ > where this_.warehouse_id=3D'IMXK' and this_.asin=3D'B002LA1D9Y' and this_= .warehouse_owner_group_id=3D1 and this_.item_disposition_code=3D'SELLABLE' > order by this_.cost_acquisition_date asc;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 QUERY PLAN=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= -------------------------------------------------- > =C2=A0Sort=C2=A0 (cost=3D50630.82..50630.84 rows=3D7 width=3D160) (actual= time=3D806.613..806.614 rows=3D5 loops=3D1) > =C2=A0=C2=A0 Sort Key: cost_acquisition_date > =C2=A0=C2=A0 Sort Method: quicksort=C2=A0 Memory: 26kB > =C2=A0=C2=A0 Buffers: shared hit=3D13110 read=3D13163 > =C2=A0=C2=A0 ->=C2=A0 Seq Scan on warehouse_costs this_=C2=A0 (cost=3D0.0= 0..50630.73 rows=3D7 width=3D160) (actual time=3D341.937..806.582 rows=3D5 = loops=3D1) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Filter: ((warehouse_owne= r_group_id =3D '1'::numeric) AND ((item_disposition_code)::text =3D 'SELLAB= LE'::text) AND ((warehouse_id)::text =3D 'IMXK'::text) AND ((asin)::text = =3D 'B002LA1D9Y'::text)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Rows Removed by Filter: = 974304 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Buffers: shared hit=3D13= 110 read=3D13163 > =C2=A0Execution time: 806.652 ms > (9 rows) >=20 > Time: 807.352 ms > testdb=3D# > testdb=3D# explain analyze > testdb-# select > testdb-# this_.warehouse_cost_id , this_.asin , this_.base_currency_code = , > testdb-# this_.cost , this_.cost_acquisition_date , this_.cost_reference_= id , > testdb-# this_.cost_reference_id_source , this_.created_by , this_.creati= on_date , > testdb-# this_.gl_product_group , this_.warehouse_fiscal_owner_id , > testdb-# this_.warehouse_owner_group_id , this_.warehouse_txn_type_id , > testdb-# this_.item_disposition_code , this_.last_updated , this_.last_up= dated_by , > testdb-# this_.last_updated_date , this_.on_hand_quantity , this_.origina= l_quantity , > testdb-# this_.record_version_number , this_.warehouse_id=C2=A0 from ware= house_costs this_ > testdb-# where this_.warehouse_id=3D'IMXK' and this_.asin=3D'B002LA1D9Y' = and this_.warehouse_owner_group_id=3D1 and this_.item_disposition_code=3D'S= ELLABLE' > testdb-# order by this_.cost_acquisition_date asc; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 QUERY PLAN=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------ > =C2=A0Sort=C2=A0 (cost=3D8.46..8.47 rows=3D1 width=3D160) (actual time=3D= 0.115..0.116 rows=3D5 loops=3D1) > =C2=A0=C2=A0 Sort Key: cost_acquisition_date > =C2=A0=C2=A0 Sort Method: quicksort=C2=A0 Memory: 26kB > =C2=A0=C2=A0 ->=C2=A0 Index Scan using i_ic_asin_whse_disp_iog_qty on war= ehouse_costs this_=C2=A0 (cost=3D0.42..8.45 rows=3D1 width=3D160) (actual t= ime=3D0.070..0.083 rows=3D5 loops=3D1) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Index Cond: ((asin =3D '= B002LA1D9Y'::bpchar) AND (warehouse_id =3D 'IMXK'::bpchar) AND ((item_dispo= sition_code)::text =3D 'SELLABLE'::text) AND (warehouse_owner_group_id =3D = '1'::numeric)) > =C2=A0Planning time: 0.530 ms > =C2=A0Execution time: 0.189 ms > (7 rows) >=20 > Time: 1.710 ms > testdb=3D# >=20 > -- > As we can see the first plan is a prepared statement and is using seq sca= n of the table and took 800 ms while the second one is with literals and in= dex scan and took 0.189 seconds. >=20 > Is there a way I can force the prepared statement to go same as the value= s with literals. >=20 > Thank you in advance! >=20 >=20 > Regards, > Virendra Kumar >=20 >=20 >=20 >=20 >=20