pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedExplain plan on a Select query
4+ messages / 3 participants
[nested] [flat]
* Explain plan on a Select query
@ 2020-03-16 16:26 John Scalia <jayknowsunix@gmail.com>
2020-03-16 18:35 ` Re: Explain plan on a Select query MichaelDBA <MichaelDBA@sqlexec.com>
2020-03-16 22:43 ` Re: Explain plan on a Select query Jeff Janes <jeff.janes@gmail.com>
0 siblings, 2 replies; 4+ messages in thread
From: John Scalia @ 2020-03-16 16:26 UTC (permalink / raw)
To: pgsql-admin
I’m a bit confused on an explain plan I just generated for a select statement. The plan’s first line begins with the word “Append” followed by the usual (cost....) data. What in the world is an Append doing here? I’ve recently performed another analyze on the table, btw.
Also, the query does not seem to be using an index, as the explain shows a pair of sequential scans, speaking of which, the second sequential scan shows it’s on a table, called <table>_test. Which is a little strange, considering that does not exist.
The query’s where clause is on a varchar(25) field. And that field has both a btree index and a trigram index on it. I’ve tried using where =, like, and ~ in order to see if I can get it to use an index. All attempts continue to say sequential scan.
—
Jay
>
Sent from my iPad
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Explain plan on a Select query
2020-03-16 16:26 Explain plan on a Select query John Scalia <jayknowsunix@gmail.com>
@ 2020-03-16 18:35 ` MichaelDBA <MichaelDBA@sqlexec.com>
1 sibling, 0 replies; 4+ messages in thread
From: MichaelDBA @ 2020-03-16 18:35 UTC (permalink / raw)
To: John Scalia <jayknowsunix@gmail.com>; +Cc: pgsql-admin
Hi John,
How many rows are in the table? If the table is small with respect to
row count, and the pages are not very fragmented, ie, not many pages,
then PG is just doing the right thing here: seq scan is less expensive
than index scan in those cases. You can turn off enable_seqscan to just
make sure it does use the index.
Regards,
Michael Vitale
John Scalia wrote on 3/16/2020 12:26 PM:
> I’m a bit confused on an explain plan I just generated for a select statement. The plan’s first line begins with the word “Append” followed by the usual (cost....) data. What in the world is an Append doing here? I’ve recently performed another analyze on the table, btw.
>
> Also, the query does not seem to be using an index, as the explain shows a pair of sequential scans, speaking of which, the second sequential scan shows it’s on a table, called <table>_test. Which is a little strange, considering that does not exist.
>
> The query’s where clause is on a varchar(25) field. And that field has both a btree index and a trigram index on it. I’ve tried using where =, like, and ~ in order to see if I can get it to use an index. All attempts continue to say sequential scan.
> —
> Jay
> Sent from my iPad
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Explain plan on a Select query
2020-03-16 16:26 Explain plan on a Select query John Scalia <jayknowsunix@gmail.com>
@ 2020-03-16 22:43 ` Jeff Janes <jeff.janes@gmail.com>
2020-03-17 00:38 ` Re: Explain plan on a Select query John Scalia <jayknowsunix@gmail.com>
1 sibling, 1 reply; 4+ messages in thread
From: Jeff Janes @ 2020-03-16 22:43 UTC (permalink / raw)
To: John Scalia <jayknowsunix@gmail.com>; +Cc: pgsql-admin
On Mon, Mar 16, 2020 at 12:26 PM John Scalia <jayknowsunix@gmail.com> wrote:
> I’m a bit confused on an explain plan I just generated for a select
> statement. The plan’s first line begins with the word “Append” followed by
> the usual (cost....) data. What in the world is an Append doing here? I’ve
> recently performed another analyze on the table, btw.
>
A top level Append would generally be used when you use a UNION ALL, or you
have inheritance.
>
> Also, the query does not seem to be using an index, as the explain shows a
> pair of sequential scans, speaking of which, the second sequential scan
> shows it’s on a table, called <table>_test. Which is a little strange,
> considering that does not exist.
>
Is that the name of the table, or the alias for that table?
"-> Seq Scan on pgbench_accounts pa_alias (cost=0.00..527869.00
rows=20000000 width=97)"
"pgbench_accounts" is the actual table, "pa_alias" is the alias for it.
PostgreSQL will create alias for table when it needs to, but I've never
seen it do so by adding "_test" to the end. Usually it adds "_" and an
integer.
It would really help to be able to see either the plan or the query, or
both.
Cheers,
Jeff
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Explain plan on a Select query
2020-03-16 16:26 Explain plan on a Select query John Scalia <jayknowsunix@gmail.com>
2020-03-16 22:43 ` Re: Explain plan on a Select query Jeff Janes <jeff.janes@gmail.com>
@ 2020-03-17 00:38 ` John Scalia <jayknowsunix@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: John Scalia @ 2020-03-17 00:38 UTC (permalink / raw)
To: Jeff Janes <jeff.janes@gmail.com>; +Cc: pgsql-admin
Well, after rebuilding the statistics on the table at least three separate times, the errant messages finally disappeared. BTW, this was on an AWS RDS instance, which I know is not the favorite of any development team member. It just threw me a bit, as the first analyze did not clear the issue.
Sent from my iPad
> On Mar 16, 2020, at 6:43 PM, Jeff Janes <jeff.janes@gmail.com> wrote:
>
>
>> On Mon, Mar 16, 2020 at 12:26 PM John Scalia <jayknowsunix@gmail.com> wrote:
>
>> I’m a bit confused on an explain plan I just generated for a select statement. The plan’s first line begins with the word “Append” followed by the usual (cost....) data. What in the world is an Append doing here? I’ve recently performed another analyze on the table, btw.
>
> A top level Append would generally be used when you use a UNION ALL, or you have inheritance.
>
>>
>> Also, the query does not seem to be using an index, as the explain shows a pair of sequential scans, speaking of which, the second sequential scan shows it’s on a table, called <table>_test. Which is a little strange, considering that does not exist.
>
> Is that the name of the table, or the alias for that table?
>
> "-> Seq Scan on pgbench_accounts pa_alias (cost=0.00..527869.00 rows=20000000 width=97)"
>
> "pgbench_accounts" is the actual table, "pa_alias" is the alias for it.
>
>
> PostgreSQL will create alias for table when it needs to, but I've never seen it do so by adding "_test" to the end. Usually it adds "_" and an integer.
>
> It would really help to be able to see either the plan or the query, or both.
>
> Cheers,
>
> Jeff
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2020-03-17 00:38 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 16:26 Explain plan on a Select query John Scalia <jayknowsunix@gmail.com>
2020-03-16 18:35 ` MichaelDBA <MichaelDBA@sqlexec.com>
2020-03-16 22:43 ` Jeff Janes <jeff.janes@gmail.com>
2020-03-17 00:38 ` John Scalia <jayknowsunix@gmail.com>
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