From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-performance@postgresql.org
Subject: Re: Query slow as Function
Date: Sat, 18 Feb 2012 17:02:44 +0100
Message-ID: <20120218160244.GA23315@tux> (raw)
In-Reply-To: <CAFLkBaWRKp7+yVdk3dCecztxEztc+YFS4ks=x3KiSWSfyDZvKw@mail.gmail.com>
References: <CAFLkBaWRKp7+yVdk3dCecztxEztc+YFS4ks=x3KiSWSfyDZvKw@mail.gmail.com>
Steve Horn <steve@stevehorn.cc> wrote:
> Execute the function: select * from geocode_carrier_route_by_geocode('xyz');
>
> This query takes 500 milliseconds to run. My question of course is why?
Wild guess:
The planner doesn't know the actual value of the input-parameter, so the
planner doesn't use the Index.
>
> Related: If I create a function and assign LANGUAGE 'sql', my function runs in
> the expected 10 milliseconds. Is there some overhead to using the plpgsql
> language?
The planner, in this case, knows the actual value.
>
> Thanks for any help in clarifying my understanding!
You can check the plan with the auto_explain - Extension, and you can
force the planner to create a plan based on the actual input-value by
using dynamic SQL (EXECUTE 'your query string' inside the function)
As i said, wild guess ...
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: akretschmer@spamfence.net
Subject: Re: Query slow as Function
In-Reply-To: <20120218160244.GA23315@tux>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox