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 1leBVM-0004vd-Bl for pgsql-performance@arkaria.postgresql.org; Wed, 05 May 2021 06:59:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1leBVL-0001yQ-AX for pgsql-performance@arkaria.postgresql.org; Wed, 05 May 2021 06:59:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1leBVK-0001yI-Ur for pgsql-performance@lists.postgresql.org; Wed, 05 May 2021 06:59:31 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1leBVD-0006Pw-Fn for pgsql-performance@postgresql.org; Wed, 05 May 2021 06:59:29 +0000 Received: by mail-oi1-x231.google.com with SMTP id i81so1307888oif.6 for ; Tue, 04 May 2021 23:59:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=enLGC28T/FRr5ymR4CThwUV8vUQM3uuNFCpSSIvkCJk=; b=g4OS1OKF3UIoKLl9VeLhV7v2kXVFTl/NxEMKc4u3eM/RJd26wIO/XZTSgMi0xqKbB/ G3rdGaAs8Snr0sEIcyLt4CMMzGBEMneNvolxtuPwoNa/pBEpH4dKxfjVW5HdaEqoBIbJ 9aMtCh3wmvWkW8d7hIF6veDAUMkzAuN7gdB2AAie3qAUBHAHCXdo6m4HUgovQhl+ljHn TVwIXxcwo2Vxrdjrdyv3lhdoyt2Og/PzAxPjZBlmLHhLu0xzvyMEZierQX3QYlpDQUHH eTovTyNRLdS9lhcBWsCD4A/Dw6Nn34IuThbGu5PoAC+7+UPkm8jJUo18AM3BVDWOCgf8 Bo5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=enLGC28T/FRr5ymR4CThwUV8vUQM3uuNFCpSSIvkCJk=; b=Uq5yVRqEM3BVHN9MaoQJ/0YnbMobJggqqnycNxK6f8G1HeuHq/IofvfZTWvTN32amN oNHJ9P71zJuDPfBQfglBGNlw/kkKtVQhwRneDtz2unwgdbzHoEc0fDTmWrBsNHNudrge HNzZu463UjAAvJIiiJy5UfIwXFyhKek3el2f4VIm0n9aMU6XKfmWstSlrY1r0BrDhNNv l0fqamcwh4TdDIWg7HIVt4L8Na9B3URVWW3P55qnE7SJK7EFHOhmNYCqgDeNycPTyE1b 4f9ZZ+n0Y8Cy2ptHyt4ay4FwKjht5ISX0nb/1dbelhJS19tNJxfTZTA7nMHOCnH7FnPi tB0A== X-Gm-Message-State: AOAM532oMjzQdDztS+WObS6TQvj3ffu1fpSpK0dxeoZTxFm/VqpqPp7N b5PIaKSzH2nbH6uNAA1/l3Jo0L19ltrLhg== X-Google-Smtp-Source: ABdhPJz3zcXkyAeEHKrOaxxPacEtumviG9gC7NQYgWcKz5qXGh3XD+7wyu3wPFBtVYxlU8NphKPt7w== X-Received: by 2002:aca:5b04:: with SMTP id p4mr20558440oib.109.1620197961981; Tue, 04 May 2021 23:59:21 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id n13sm477260oop.8.2021.05.04.23.59.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 May 2021 23:59:21 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 12293800B42; Wed, 5 May 2021 01:59:20 -0500 (CDT) Date: Wed, 5 May 2021 01:59:19 -0500 From: Justin Pryzby To: Alex Cc: pgsql-performance@postgresql.org Subject: Re: 15x slower PreparedStatement vs raw query Message-ID: <20210505065919.GQ27406@telsasoft.com> References: <3f8c88d8a6ef9.d82fa04cf610d.ref@yahoo.com> <3f8c88d8a6ef9.d82fa04cf610d@yahoo.com> <20210503201811.GA27406@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210503201811.GA27406@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, May 03, 2021 at 03:18:11PM -0500, Justin Pryzby wrote: > On Sun, May 02, 2021 at 07:45:26PM +0000, Alex wrote: > > PreparedStatement: 15s > > Raw query with embedded params: 1s > > See issue on github with query and explain analyze: > > https://github.com/pgjdbc/pgjdbc/issues/2145 > > | ..PostgreSQL Version? 12 > |Prepared statement > |... > |Planning Time: 11.596 ms > |Execution Time: 14799.266 ms > | > |Raw statement > |Planning Time: 22.685 ms > |Execution Time: 1012.992 ms > > The prepared statemnt has 2x faster planning time, which is what it's meant to > improve. > > The execution time is slower, and I think you can improve it with this. > https://www.postgresql.org/docs/12/runtime-config-query.html#GUC-PLAN-CACHE_MODE Also, the rowcount estimates are way off starting with the scan nodes. -> Bitmap Heap Scan on category_property_name cpn_limits (cost=32.13..53.55 rows=14 width=29) (actual time=0.665..8.822 rows=2650 loops=1) Recheck Cond: ((lexeme = ANY ('{''rata'',""''polling'' ''rata'' ''ratez''"",""''polling'' ''rata''"",""''rata'' ''ratez'' ''semnal'' ''usb-ul''""}'::tsvector[])) OR (lexeme = '''frecventa'' ''frecventez'''::tsvector) OR (lexeme = '''raportare'' ''rata'' ''ratez'''::tsvector) OR (lexeme = ANY ('{''latime'',""''latime'' ''placi''"",""''compatibila'' ''latime'' ''telefon''""}'::tsvector[])) OR (lexeme = '''lungime'''::tsvector) OR (lexeme = '''cablu'' ''lungime'''::tsvector) OR (lexeme = '''inaltime'''::tsvector) OR (lexeme = '''rezolutie'''::tsvector) OR (lexeme = '''greutate'''::tsvector)) Heap Blocks: exact=85 -> BitmapOr (cost=32.13..32.13 rows=14 width=0) (actual time=0.574..0.577 rows=0 loops=1) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..9.17 rows=4 width=0) (actual time=0.088..0.089 rows=10 loops=1) Index Cond: (lexeme = ANY ('{''rata'',""''polling'' ''rata'' ''ratez''"",""''polling'' ''rata''"",""''rata'' ''ratez'' ''semnal'' ''usb-ul''""}'::tsvector[])) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..2.29 rows=1 width=0) (actual time=0.047..0.047 rows=171 loops=1) Index Cond: (lexeme = '''frecventa'' ''frecventez'''::tsvector) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..2.29 rows=1 width=0) (actual time=0.015..0.015 rows=1 loops=1) Index Cond: (lexeme = '''raportare'' ''rata'' ''ratez'''::tsvector) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..6.88 rows=3 width=0) (actual time=0.097..0.097 rows=547 loops=1) Index Cond: (lexeme = ANY ('{''latime'',""''latime'' ''placi''"",""''compatibila'' ''latime'' ''telefon''""}'::tsvector[])) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..2.29 rows=1 width=0) (actual time=0.107..0.107 rows=604 loops=1) Index Cond: (lexeme = '''lungime'''::tsvector) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..2.29 rows=1 width=0) (actual time=0.030..0.030 rows=137 loops=1) Index Cond: (lexeme = '''cablu'' ''lungime'''::tsvector) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..2.29 rows=1 width=0) (actual time=0.079..0.079 rows=479 loops=1) Index Cond: (lexeme = '''inaltime'''::tsvector) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..2.29 rows=1 width=0) (actual time=0.020..0.020 rows=40 loops=1) Index Cond: (lexeme = '''rezolutie'''::tsvector) -> Bitmap Index Scan on category_property_name_lexeme_idx (cost=0.00..2.29 rows=1 width=0) (actual time=0.088..0.088 rows=661 loops=1) Index Cond: (lexeme = '''greutate'''::tsvector)