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 1ldvoC-0007nb-QY for pgsql-performance@arkaria.postgresql.org; Tue, 04 May 2021 14:13:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ldvoB-0001iy-OP for pgsql-performance@arkaria.postgresql.org; Tue, 04 May 2021 14:13:55 +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 1ldvaF-0006cY-Hi for pgsql-performance@lists.postgresql.org; Tue, 04 May 2021 13:59:31 +0000 Received: from sonic301-31.consmr.mail.ne1.yahoo.com ([66.163.184.200]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ldvaC-000606-Sl for pgsql-performance@postgresql.org; Tue, 04 May 2021 13:59:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1620136767; bh=OR6cmq+WoGGacNYXOPDteQYTHARaKnlU5iozGWjT+MI=; h=From:Subject:To:Cc:References:Date:From:Subject:Reply-To; b=pIg5Efc/Yv8fNvab4v4Tqgwe1teYJzjDR51tiZLo0Mzf72UACQ3hbgw4v3LRSaZ004PhFTR0t6+NMI61nc65OWZu2lecRgWr4mK8EPGJQ8ghxgQ1GtxwlE+idk1gGNd9pTBcRqCG6OMcr2KNolluN/c2gP/Dok17ZvHksCnzFtV40AYALv+XictY3YRMpq9mjK2YKtLinh2gxDxeRd9udJXaeULoebU7dPJsXAln1pPRqjlj41Rn683Y0//BCIY1PkhcZGIzZgS+aZQ6+fmzxXfnZFbH3G525dbKjNc/sdRIYVBsX7bnCaaFXhykSWAQbv2+bgjSAmGUKWL2/YytxA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1620136767; bh=Wrx6LQDDShkoRBoPf7XFHtwJ5Xy/YP4NQssOD38v7Ql=; h=X-Sonic-MF:From:Subject:To:Date:From:Subject; b=TRgQecuckrcdQPSzAIGAKEc/tHGC9NVMwaaWg2fXiRop5eWvObLjqgqJoYTz5EL2mq0e8q+MdqO4qVwlFcR/5107j86/O0K3z1kV/zIMKljpVD4IZHFWhMs/V9DlE5WTGXDsSt3GDCnuhMdg1VKd2kYoUziHHMrOB7at+XLd2KClVJwabJ8gGDc30uRJYkIwtDbJ4eYU4Sd9CISFS8aaAd4KSrKCmSxUkdExXEqaRsDJxblwdgvisxuepibNlMRzDl4VawCOjeCEaEARoluQ8BBE9XiywkCatbx7ZSWKHhx0mRmhRZfJq1zkqoa1ghuIATUAgYV1H6wMS68W11tCbQ== X-YMail-OSG: x622mk4VM1lJWUjoyC7cjpxIJYVHxopDxdi9DHmOgl.SWYRRM1osRzcyjv3YT3A omYHvYkOq0yENZcLvkSwot3wA_126Llf4WHWRa8Ce2Z91NggvOaenGJ17a76izWdIVh2s_RikzEf 9fPi53epJwIZdaqCZrM6aT1WXhT.THtmMv0luLLwFl6JnSyeU16w7uKUTv_O00AJrAAgXGgjBe0y 76Mk37cfdaa9qu149adQpwLBc_ZDdIDv9rpKk21GBYeMUWvrSCyKVVWk0ZxudutWkacC6GgICDk4 VmH7WlyF2gGz8sx10GVztLj6r1IlHr6WD2nhoo9pYBNGImJiVGoqfVRwhOfudSfrWeCHpxx4JCxr jyZzu7xBAp7_GIbHyrrHsyWrr1XQuOfLbduDYd673UXpuUpqP3bZg5x2EueI_o1Vgl_Flrnr082o FNEmHCklzLmb8JgM8XRbWxlVCwBQ0pNieunx6MIkrI3v_zEx_4p4LJ7KVBOYe4.ADTBrMBrxjjUE y3UKV2rgYExmO9jHc_ZjGx0usrWDbPK3btXL2HhL5e4ptrh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o.com with HTTP; Tue, 4 May 2021 13:59:27 +0000 Received: by kubenode519.mail-prod1.omega.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 690f0238e5d7b161b8f2ec6029099ad5; Tue, 04 May 2021 13:59:19 +0000 (UTC) Content-Type: multipart/alternative; boundary="----sinikael-?=_1-16201367573870.026728409517000618" From: Alex Subject: Re: 15x slower PreparedStatement vs raw query X-Type: replyAll To: Rick Otten Cc: Justin Pryzby , "pgsql-performa." User-Agent: Desktop Message-Id: <6cd0e931a59e1.4c58a67a1e5f6@yahoo.com> References: <3f8c88d8a6ef9.d82fa04cf610d.ref@yahoo.com> <3f8c88d8a6ef9.d82fa04cf610d@yahoo.com> <20210503201811.GA27406@telsasoft.com> <49daf090ac5b1.96e1ada6021ee@yahoo.com> Content-Transfer-Encoding: quoted-printable Date: Tue, 04 May 2021 13:59:16 +0000 MIME-Version: 1.0 X-Mailer: WebService/1.1.18231 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Apache-HttpAsyncClient/4.1.4 (Java/16) Content-Length: 5521 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------sinikael-?=_1-16201367573870.026728409517000618 Content-Type: text/plain; format=flowed Content-Transfer-Encoding: 7bit "Powerful general purpose relational database" but not smart... I propose a feature to use information from previously executed queries to adjust the query plan time accordingly. Reusing the same generic plan may and will lead to very long execution times. Rick Otten wrote: On Tue, May 4, 2021 at 6:05 AM Alex > wrote: Shouldn't this process be automatic based on some heuristics? Saving 10ms planning but costing 14s execution is catastrophic. For example, using some statistics to limit planner time to some percent of of previous executions. This way, if query is fast, planning is fast, but if query is slow, more planning can save huge execution time. This is a better general usage option and should be enabled by default, and users who want fast planning should set the variable to use the generic plan. "fast" and "slow" are relative things. There are many queries that I would be overjoyed with if they completed in 5 _minutes_. And others where they have to complete within 100ms or something is really wrong. We don't really know what the execution time is until the query actually executes. Planning is a guess for the best approach. Another factor is whether the data is in cache or out on disk. Sometimes you don't really know until you try to go get it. That can significantly change query performance and plans - especially if some of the tables in a query with a lot of joins are in cache and some aren't and maybe some have to be swapped out to pick up others. If you are running the same dozen queries with different but similarly scoped parameters over and over, one would hope that the system would slowly tune itself to be highly optimized for those dozen queries. That is a pretty narrow use case for a powerful general purpose relational database though. ------sinikael-?=_1-16201367573870.026728409517000618 Content-Type: text/html; format=flowed Content-Transfer-Encoding: 7bit
"Powerful general purpose relational database" but not smart... 

I propose a feature to use information from previously executed queries to adjust the query plan time accordingly.
Reusing the same generic plan may and will lead to very long execution times.



Rick Otten wrote:




On Tue, May 4, 2021 at 6:05 AM Alex <cdalxndr@yahoo.com> wrote:
Shouldn't this process be automatic based on some heuristics?

Saving 10ms planning but costing 14s execution is catastrophic.

For example, using some statistics to limit planner time to some percent of of previous executions. 
This way, if query is fast, planning is fast, but if query is slow, more planning can save huge execution time.
This is a better general usage option and should be enabled by default, and users who want fast planning should set the variable to use the generic plan.



"fast" and "slow" are relative things.  There are many queries that I would be overjoyed with if they completed in 5 _minutes_.  And others where they have to complete within 100ms or something is really wrong.  We don't really know what the execution time is until the query actually executes.  Planning is a guess for the best approach.

Another factor is whether the data is in cache or out on disk.  Sometimes you don't really know until you try to go get it.  That can significantly change query performance and plans - especially if some of the tables in a query with a lot of joins are in cache and some aren't and maybe some have to be swapped out to pick up others.

If you are running the same dozen queries with different but similarly scoped parameters over and over, one would hope that the system would slowly tune itself to be highly optimized for those dozen queries.  That is a pretty narrow use case for a powerful general purpose relational database though.

------sinikael-?=_1-16201367573870.026728409517000618--