Index Scans become Seq Scans after VACUUM ANALYSE

Started by Louis-David Mitterrandalmost 24 years ago206 messageshackers
Jump to latest
#1Louis-David Mitterrand
vindex@apartia.org

Hello,

While trying to optimise a query I found that running VACUUM ANALYSE
changed all the Index Scans to Seq Scans and that the only way to revert
to Index Scans was the add "enable_seqscan = 0" in postgresql.conf.

Seq Scans are much slower for that specific query. Why does Postgres
switch to that method?

PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.95.4
(1 row)

Output with "enable_seqscan = 0":

gesci5=# explain select p.id_prospect, p.position_prospect, initcap(p1.nom) as nom, initcap(p1.prenom) as prenom, a1.no_tel, a1.no_portable, p.dernier_contact, cn.id_contact, cn.id_vendeur, cn.id_operation, case when p.dernier_contact is not null then cn.date_contact::abstime::int4 else p.cree_le::abstime::int4 end as date_contact, cn.type_contact, cn.nouveau_rdv::abstime::int4 as nouveau_rdv, cn.date_echeance::abstime::int4 as date_echeance, cn.date_reponse::abstime::int4 as date_reponse from prospect p left join personne p1 on (p1.id_personne = p.id_personne1) left join adresse a1 on (a1.id_adresse = p1.id_adresse_principale) left join contact cn on (p.dernier_contact = cn.id_contact) where (p.abandon is null or p.abandon != 'O') order by cn.date_contact desc;
NOTICE: QUERY PLAN:

Sort (cost=49442.99..49442.99 rows=24719 width=123)
-> Hash Join (cost=14146.79..46656.05 rows=24719 width=123)
-> Merge Join (cost=9761.33..40724.83 rows=24719 width=66)
-> Sort (cost=9761.33..9761.33 rows=24719 width=49)
-> Merge Join (cost=0.00..7485.53 rows=24719 width=49)
-> Index Scan using prospect_personne1 on prospect p (cost=0.00..4322.18 rows=24719 width=22)
-> Index Scan using personne_pkey on personne p1 (cost=0.00..2681.90 rows=44271 width=27)
-> Index Scan using adresse_pkey on adresse a1 (cost=0.00..30354.16 rows=95425 width=17)
-> Hash (cost=3242.09..3242.09 rows=30224 width=57)
-> Index Scan using contact_pkey on contact cn (cost=0.00..3242.09 rows=30224 width=57)

Output with "enable_seqscan = 1":

Sort (cost=18622.67..18622.67 rows=24719 width=123)
-> Hash Join (cost=10034.30..15835.73 rows=24719 width=123)
-> Hash Join (cost=8074.99..12330.65 rows=24719 width=66)
-> Hash Join (cost=2088.54..4629.65 rows=24719 width=49)
-> Seq Scan on prospect p (cost=0.00..1289.35 rows=24719 width=22)
-> Hash (cost=1106.71..1106.71 rows=44271 width=27)
-> Seq Scan on personne p1 (cost=0.00..1106.71 rows=44271 width=27)
-> Hash (cost=2561.25..2561.25 rows=95425 width=17)
-> Seq Scan on adresse a1 (cost=0.00..2561.25 rows=95425 width=17)
-> Hash (cost=1036.24..1036.24 rows=30224 width=57)
-> Seq Scan on contact cn (cost=0.00..1036.24 rows=30224 width=57)

--
OENONE: Rebelle � tous nos soins, sourde � tous nos discours,
Voulez-vous sans piti� laisser finir vos jours ?
(Ph�dre, J-B Racine, acte 1, sc�ne 3)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Louis-David Mitterrand (#1)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Louis-David Mitterrand <vindex@apartia.org> writes:

While trying to optimise a query I found that running VACUUM ANALYSE
changed all the Index Scans to Seq Scans and that the only way to revert
to Index Scans was the add "enable_seqscan = 0" in postgresql.conf.

EXPLAIN ANALYZE output would be more interesting than just EXPLAIN.
Also, what does the pg_stats view show for these tables?

regards, tom lane

#3Louis-David Mitterrand
vindex@apartia.org
In reply to: Tom Lane (#2)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

On Tue, Apr 16, 2002 at 10:41:57AM -0400, Tom Lane wrote:

Louis-David Mitterrand <vindex@apartia.org> writes:

While trying to optimise a query I found that running VACUUM ANALYSE
changed all the Index Scans to Seq Scans and that the only way to revert
to Index Scans was the add "enable_seqscan = 0" in postgresql.conf.

EXPLAIN ANALYZE output would be more interesting than just EXPLAIN.
Also, what does the pg_stats view show for these tables?

Thanks, pg_stats output is rather big so I attached it in a separate
file. Here are the EXPLAIN ANALYZE ouputs:

*********************************
* 1) With "enable_seqscan = 0": *
*********************************

gesci5=# explain analyse select p.id_prospect, p.position_prospect, initcap(p1.nom) as nom, initcap(p1.prenom) as prenom, a1.no_tel, a1.no_portable, p.dernier_contact, cn.id_contact, cn.id_vendeur, cn.id_operation, case when p.dernier_contact is not null then cn.date_contact::abstime::int4 else p.cree_le::abstime::int4 end as date_contact, cn.type_contact, cn.nouveau_rdv::abstime::int4 as nouveau_rdv, cn.date_echeance::abstime::int4 as date_echeance, cn.date_reponse::abstime::int4 as date_reponse from prospect p left join personne p1 on (p1.id_personne = p.id_personne1) left join adresse a1 on (a1.id_adresse = p1.id_adresse_principale) left join contact cn on (p.dernier_contact = cn.id_contact) where (p.abandon is null or p.abandon != 'O') order by cn.date_contact desc;
NOTICE: QUERY PLAN:

Sort (cost=49442.99..49442.99 rows=24719 width=123) (actual time=7281.98..7319.91 rows=23038 loops=1)
-> Hash Join (cost=14146.79..46656.05 rows=24719 width=123) (actual time=2619.85..6143.47 rows=23038 loops=1)
-> Merge Join (cost=9761.33..40724.83 rows=24719 width=66) (actual time=2061.31..3362.49 rows=23038 loops=1)
-> Sort (cost=9761.33..9761.33 rows=24719 width=49) (actual time=1912.73..1961.61 rows=23038 loops=1)
-> Merge Join (cost=0.00..7485.53 rows=24719 width=49) (actual time=42.98..1264.63 rows=23038 loops=1)
-> Index Scan using prospect_personne1 on prospect p (cost=0.00..4322.18 rows=24719 width=22) (actual time=0.28..528.42 rows=23038 loops=1)
-> Index Scan using personne_pkey on personne p1 (cost=0.00..2681.90 rows=44271 width=27) (actual time=0.18..384.11 rows=44302 loops=1)
-> Index Scan using adresse_pkey on adresse a1 (cost=0.00..30354.16 rows=95425 width=17) (actual time=0.44..738.99 rows=95456 loops=1)
-> Hash (cost=3242.09..3242.09 rows=30224 width=57) (actual time=557.04..557.04 rows=0 loops=1)
-> Index Scan using contact_pkey on contact cn (cost=0.00..3242.09 rows=30224 width=57) (actual time=0.26..457.97 rows=30224 loops=1)
Total runtime: 7965.74 msec

EXPLAIN

*********************************
* 2) With "enable_seqscan = 1": *
*********************************

NOTICE: QUERY PLAN:

Sort (cost=18622.67..18622.67 rows=24719 width=123) (actual time=10329.09..10367.06 rows=23039 loops=1)
-> Hash Join (cost=10034.30..15835.73 rows=24719 width=123) (actual time=1644.04..9397.53 rows=23039 loops=1)
-> Hash Join (cost=8074.99..12330.65 rows=24719 width=66) (actual time=1110.05..6475.65 rows=23039 loops=1)
-> Hash Join (cost=2088.54..4629.65 rows=24719 width=49) (actual time=385.33..2763.91 rows=23039 loops=1)
-> Seq Scan on prospect p (cost=0.00..1289.35 rows=24719 width=22) (actual time=0.34..361.31 rows=23039 loops=1)
-> Hash (cost=1106.71..1106.71 rows=44271 width=27) (actual time=381.91..381.91 rows=0 loops=1)
-> Seq Scan on personne p1 (cost=0.00..1106.71 rows=44271 width=27) (actual time=0.15..246.32 rows=44272 loops=1)
-> Hash (cost=2561.25..2561.25 rows=95425 width=17) (actual time=723.15..723.15 rows=0 loops=1)
-> Seq Scan on adresse a1 (cost=0.00..2561.25 rows=95425 width=17) (actual time=0.17..452.55 rows=95427 loops=1)
-> Hash (cost=1036.24..1036.24 rows=30224 width=57) (actual time=532.87..532.87 rows=0 loops=1)
-> Seq Scan on contact cn (cost=0.00..1036.24 rows=30224 width=57) (actual time=2.54..302.49 rows=30225 loops=1)
Total runtime: 10901.85 msec

EXPLAIN

--
HIPPOLYTE: Mais quels soins d�sormais peuvent me retarder ?
Assez dans les for�ts mon oisive jeunesse
Sur de vils ennemis a montr� son adresse.
(Ph�dre, J-B Racine, acte 3, sc�ne 5)

Attachments:

pg_stats.txttext/plain; charset=iso-8859-1Download
#4Michael Loftis
mloftis@wgops.com
In reply to: Louis-David Mitterrand (#1)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Reading all of this discussion lately about how the planner seems to
prefer seqscan's in alot of places where indexes would be better starts
making me wonder if some of the assumptions or cals made to figure costs
are wrong...

Anyone have any ideas?

Louis-David Mitterrand wrote:

Show quoted text

On Tue, Apr 16, 2002 at 10:41:57AM -0400, Tom Lane wrote:

Louis-David Mitterrand <vindex@apartia.org> writes:

While trying to optimise a query I found that running VACUUM ANALYSE
changed all the Index Scans to Seq Scans and that the only way to revert
to Index Scans was the add "enable_seqscan = 0" in postgresql.conf.

EXPLAIN ANALYZE output would be more interesting than just EXPLAIN.
Also, what does the pg_stats view show for these tables?

Thanks, pg_stats output is rather big so I attached it in a separate
file. Here are the EXPLAIN ANALYZE ouputs:

... SNIP ...

#5Michael Loftis
mloftis@wgops.com
In reply to: Louis-David Mitterrand (#1)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

I know I know, replying to myself is bad and probably means I'm going
insane but thought of one other thing...

Realistically the system should choos *ANY* index over a sequential
table scan. Above a fairly low number of records any indexed query
should be much faster than a seqscan. Am I right, or did I miss
something? (wouldn't be the first time I missed something)... Right
now the planner seems to think that index queries are more expensive
with a larger width than doing a seqscan on (possibly) more rows with a
narrower width.

Michael Loftis wrote:

Show quoted text

Reading all of this discussion lately about how the planner seems to
prefer seqscan's in alot of places where indexes would be better
starts making me wonder if some of the assumptions or cals made to
figure costs are wrong...

Anyone have any ideas?

Louis-David Mitterrand wrote:

On Tue, Apr 16, 2002 at 10:41:57AM -0400, Tom Lane wrote:

Louis-David Mitterrand <vindex@apartia.org> writes:

While trying to optimise a query I found that running VACUUM ANALYSE
changed all the Index Scans to Seq Scans and that the only way to
revert
to Index Scans was the add "enable_seqscan = 0" in postgresql.conf.

EXPLAIN ANALYZE output would be more interesting than just EXPLAIN.
Also, what does the pg_stats view show for these tables?

Thanks, pg_stats output is rather big so I attached it in a separate
file. Here are the EXPLAIN ANALYZE ouputs:

... SNIP ...

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

#6Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Michael Loftis (#5)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

On Tue, 16 Apr 2002, Michael Loftis wrote:

I know I know, replying to myself is bad and probably means I'm going
insane but thought of one other thing...

Realistically the system should choos *ANY* index over a sequential
table scan. Above a fairly low number of records any indexed query
should be much faster than a seqscan. Am I right, or did I miss
something? (wouldn't be the first time I missed something)... Right

Because the validity information is stored with the row and not the index
you have to read rows for any potential hit in the index. Depending on
the clustering of the table, the width of the rows and the percentage of
the table being hit by the scan (or estimated to be hit) you may read
most or all of the table as well as the index and be paying a penalty for
doing it randomly as opposed to be sequentially. IIRC, there are some
settings in the configuration that let you play around with the relative
costs the estimator uses (the random page cost and cpu costs for dealing
with index entries and such).

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Loftis (#4)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Michael Loftis <mloftis@wgops.com> writes:

Reading all of this discussion lately about how the planner seems to
prefer seqscan's in alot of places where indexes would be better starts
making me wonder if some of the assumptions or cals made to figure costs
are wrong...

Could well be. The sources are open, feel free to take a look ...
src/backend/optimizer/path/costsize.c is the epicenter ...

regards, tom lane

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Loftis (#5)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Michael Loftis <mloftis@wgops.com> writes:

Realistically the system should choos *ANY* index over a sequential
table scan.

Sorry, I do not accept that. You might as well say that we should
rip out any attempt at cost estimation, and instead put in two or
three lines of brain-dead heuristics. If it were that simple we'd
all be using MySQL ;-)

Above a fairly low number of records any indexed query
should be much faster than a seqscan.

Isn't that exactly backwards?

regards, tom lane

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Louis-David Mitterrand (#3)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Louis-David Mitterrand <vindex@apartia.org> writes:

While trying to optimise a query I found that running VACUUM ANALYSE
changed all the Index Scans to Seq Scans and that the only way to revert
to Index Scans was the add "enable_seqscan = 0" in postgresql.conf.

EXPLAIN ANALYZE output would be more interesting than just EXPLAIN.
Also, what does the pg_stats view show for these tables?

Thanks, pg_stats output is rather big so I attached it in a separate
file. Here are the EXPLAIN ANALYZE ouputs:

Tell you the truth, I'm having a real hard time getting excited over
a bug report that says the planner chose a plan taking 10.90 seconds
in preference to one taking 7.96 seconds.

Any time the planner's estimates are within a factor of 2 of reality,
I figure it's done very well. The inherent unknowns are so large that
that really amounts to divination. We can't expect to choose a perfect
plan every time --- if we can avoid choosing a truly stupid plan (say,
one that takes a couple orders of magnitude more time than the best
possible plan) then we ought to be happy.

But having said that, it would be interesting to see if adjusting some
of the planner cost parameters would yield better results in your
situation. The coarsest of these is random_page_cost, which is
presently 4.0 by default. Although I have done some moderately
extensive measurements to get that figure, other folks have reported
that lower numbers like 3.0 or even less seem to suit their platforms
better. In general a lower random_page_cost will favor indexscans...

regards, tom lane

#10Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#9)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Let me add people's expections of the optimizer and the "it isn't using
the index" questions are getting very old. I have beefed up the FAQ
item on this a month ago, but that hasn't reduced the number of
questions. I almost want to require people to read a specific FAQ item
4.8 before we will reply to anything.

Maybe that FAQ item needs more info. Tom can't be running around trying
to check all these optimizer reports when >90% are just people not
understanding the basics of optimization or query performance.

Maybe we need an optimizer FAQ that will answer the basic questions for
people.

---------------------------------------------------------------------------

Tom Lane wrote:

Louis-David Mitterrand <vindex@apartia.org> writes:

While trying to optimise a query I found that running VACUUM ANALYSE
changed all the Index Scans to Seq Scans and that the only way to revert
to Index Scans was the add "enable_seqscan = 0" in postgresql.conf.

EXPLAIN ANALYZE output would be more interesting than just EXPLAIN.
Also, what does the pg_stats view show for these tables?

Thanks, pg_stats output is rather big so I attached it in a separate
file. Here are the EXPLAIN ANALYZE ouputs:

Tell you the truth, I'm having a real hard time getting excited over
a bug report that says the planner chose a plan taking 10.90 seconds
in preference to one taking 7.96 seconds.

Any time the planner's estimates are within a factor of 2 of reality,
I figure it's done very well. The inherent unknowns are so large that
that really amounts to divination. We can't expect to choose a perfect
plan every time --- if we can avoid choosing a truly stupid plan (say,
one that takes a couple orders of magnitude more time than the best
possible plan) then we ought to be happy.

But having said that, it would be interesting to see if adjusting some
of the planner cost parameters would yield better results in your
situation. The coarsest of these is random_page_cost, which is
presently 4.0 by default. Although I have done some moderately
extensive measurements to get that figure, other folks have reported
that lower numbers like 3.0 or even less seem to suit their platforms
better. In general a lower random_page_cost will favor indexscans...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#11mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Bruce Momjian wrote:

Let me add people's expections of the optimizer and the "it isn't using
the index" questions are getting very old. I have beefed up the FAQ
item on this a month ago, but that hasn't reduced the number of
questions. I almost want to require people to read a specific FAQ item
4.8 before we will reply to anything.

Maybe that FAQ item needs more info. Tom can't be running around trying
to check all these optimizer reports when >90% are just people not
understanding the basics of optimization or query performance.

Maybe we need an optimizer FAQ that will answer the basic questions for
people.

I think you are missing a huge point, people are confused by the operation of
PostgreSQL. You admit that there are a lot of questions about this topic. This
means that something is happening which is non-intuitive. Bruce, you are an
expert in PostgreSQL, but most people who use it are not. The unexpected
behavior is just that, unexpected, or a surprise.

Business people, accountants, and engineers do not like surprises. PostgreSQL's
behavior on index usage is totally confusing. If I can paraphase correctly,
PostgreSQL wants to have a good reason to use an index. Most people expect a
database to have an undeniable reason NOT to use an index. I would also say, if
a DBA created an index, there is a strong indication that there is a need for
one! (DBA knowledge vs statistics)

That is the difference, in another post Tom said he could not get excited about
10.9 second execution time over a 7.96 execution time. Damn!!! I would. That is
wrong.

I have bitched about the index stuff for a while, and always have bumped up
against this problem. If I can sway anyone's opinion, I would say, unless
(using Tom's words) a "factor of 2" planner difference against, I would use an
index. Rather than needing clear evidence to use an index, I would say you need
clear evidence not too.

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: mlw (#11)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

mlw <markw@mohawksoft.com> writes:

That is the difference, in another post Tom said he could not get
excited about 10.9 second execution time over a 7.96 execution
time. Damn!!! I would. That is wrong.

Sure. Show us how to make the planner's estimates 2x more accurate
(on average) than they are now, and I'll get excited too.

But forcing indexscan to be chosen over seqscan does not count as
making it more accurate. (If you think it does, then you don't
need to be in this thread at all; set enable_seqscan = 0 and
stop bugging us ;-))

regards, tom lane

#13Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: mlw (#11)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

I have bitched about the index stuff for a while, and always have
bumped up
against this problem. If I can sway anyone's opinion, I would say, unless
(using Tom's words) a "factor of 2" planner difference against, I
would use an
index. Rather than needing clear evidence to use an index, I
would say you need
clear evidence not too.

I spend a lot of time answering questions on various database forums and I
find that the single thing that most newbies just cannot understand is that
a sequential scan is often a lot faster than an index scan. They just
cannot comprehend that an index can be slower. Ever. For any query. That
is not our problem...

What we could offer tho, is more manual control over the planner. People
can do this to a mild extend by disabling sequential scans, but it looks
like it should be extended...

Chris

#14mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Tom Lane wrote:

mlw <markw@mohawksoft.com> writes:

That is the difference, in another post Tom said he could not get
excited about 10.9 second execution time over a 7.96 execution
time. Damn!!! I would. That is wrong.

Sure. Show us how to make the planner's estimates 2x more accurate
(on average) than they are now, and I'll get excited too.

But forcing indexscan to be chosen over seqscan does not count as
making it more accurate. (If you think it does, then you don't
need to be in this thread at all; set enable_seqscan = 0 and
stop bugging us ;-))

Oh, come on Tom, surely I have been around long enough to lend credence that
wish to have a positive affect on PostgreSQL development.

enable_seqscan=0, disallows sequential scan, that is not what I am saying. This
is a problem I (and others) have been yapping about for a long time.

(Please remember, I USE PostgreSQL, I have a vested interest in it being the
best RDBMS available.)

I just think there is sufficient evidence to suggest that if a DBA creates an
index, there is strong evidence (better than statistics) that the index need be
used. In the event that an index exists, there is a strong indication that,
without overwhelming evidence, that the index should be used. You have admitted
that statistics suck, but the existence of an index must weight (heavily) on
the evaluation on whether or not to use an index.

#15mlw
markw@mohawksoft.com
In reply to: Christopher Kings-Lynne (#13)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Christopher Kings-Lynne wrote:

I have bitched about the index stuff for a while, and always have
bumped up
against this problem. If I can sway anyone's opinion, I would say, unless
(using Tom's words) a "factor of 2" planner difference against, I
would use an
index. Rather than needing clear evidence to use an index, I
would say you need
clear evidence not too.

I spend a lot of time answering questions on various database forums and I
find that the single thing that most newbies just cannot understand is that
a sequential scan is often a lot faster than an index scan. They just
cannot comprehend that an index can be slower. Ever. For any query. That
is not our problem...

Here is the problem, in a single paragraph.

If the DBA notices that there is a problem with a query, he adds an index, he
notices that there is no difference, then he notices that PostgreSQL is not
using his index. First and foremost he gets mad at PostgreSQL for not using his
index. If PostgreSQL decided to use an index which increases execution time,
the DBA would delete the index. If PostgreSQL does not use an index, he has to
modify the posgresql.conf file, which disallows PostgreSQL from using an index
when it would be a clear loser.

My assertion is this: "If a DBA creates an index, he has a basis for his
actions."

#16Oliver Elphick
olly@lfix.co.uk
In reply to: mlw (#14)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

On Wed, 2002-04-17 at 06:51, mlw wrote:

I just think there is sufficient evidence to suggest that if a DBA creates an
index, there is strong evidence (better than statistics) that the index need be
used. In the event that an index exists, there is a strong indication that,
without overwhelming evidence, that the index should be used. You have admitted
that statistics suck, but the existence of an index must weight (heavily) on
the evaluation on whether or not to use an index.

But indexes are not, for the most part, there because of a specific
choice to have an index, but as the implementation of PRIMARY KEY and
UNIQUE. Therefore the main part of your argument fails.

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C

"But as many as received him, to them gave he power to
become the sons of God, even to them that believe on
his name." John 1:12

#17Oliver Elphick
olly@lfix.co.uk
In reply to: mlw (#14)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

On Wed, 2002-04-17 at 06:51, mlw wrote:

I just think there is sufficient evidence to suggest that if a DBA creates an
index, there is strong evidence (better than statistics) that the index need be
used. In the event that an index exists, there is a strong indication that,
without overwhelming evidence, that the index should be used. You have admitted
that statistics suck, but the existence of an index must weight (heavily) on
the evaluation on whether or not to use an index.

But indexes are not, for the most part, there because of a specific
choice to have an index, but as the implementation of PRIMARY KEY and
UNIQUE. Therefore the main part of your argument fails.

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C

"But as many as received him, to them gave he power to
become the sons of God, even to them that believe on
his name." John 1:12

#18mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

Oliver Elphick wrote:

On Wed, 2002-04-17 at 06:51, mlw wrote:

I just think there is sufficient evidence to suggest that if a DBA creates an
index, there is strong evidence (better than statistics) that the index need be
used. In the event that an index exists, there is a strong indication that,
without overwhelming evidence, that the index should be used. You have admitted
that statistics suck, but the existence of an index must weight (heavily) on
the evaluation on whether or not to use an index.

But indexes are not, for the most part, there because of a specific
choice to have an index, but as the implementation of PRIMARY KEY and
UNIQUE. Therefore the main part of your argument fails.

Let's talk about the primary key, that will not exhibit the borderline behavior
that we see. I have had first hand experience (and frustration) on PostgreSQL's
choice of using an index.

The primary key and UNIQUE constraint will only exhibit reduced performance on
REALLY small tables, in which case, the reduced performance is minimal if not
nonexistent.

#19Hannu Krosing
hannu@tm.ee
In reply to: mlw (#15)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

On Wed, 2002-04-17 at 11:00, mlw wrote:

Here is the problem, in a single paragraph.

If the DBA notices that there is a problem with a query, he adds an index, he
notices that there is no difference, then he notices that PostgreSQL is not
using his index. First and foremost he gets mad at PostgreSQL for not using his
index.

Perhaps a notice from backend:

NOTICE: I see the DBA has created a useless index ...

;)

Or would this make the DBA even madder ;) ;)

If PostgreSQL decided to use an index which increases execution time,
the DBA would delete the index. If PostgreSQL does not use an index, he has to
modify the posgresql.conf file,

Or just do

set enable_seqscan to off;

which disallows PostgreSQL from using an index when it would be a clear loser.

My assertion is this: "If a DBA creates an index, he has a basis for his
actions."

The basis can be that "his boss told him to" ?

------------------
Hannu

#20Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: mlw (#15)
Re: Index Scans become Seq Scans after VACUUM ANALYSE

If the DBA notices that there is a problem with a query, he adds
an index, he
notices that there is no difference, then he notices that
PostgreSQL is not
using his index. First and foremost he gets mad at PostgreSQL for
not using his
index. If PostgreSQL decided to use an index which increases
execution time,
the DBA would delete the index. If PostgreSQL does not use an
index, he has to
modify the posgresql.conf file, which disallows PostgreSQL from
using an index
when it would be a clear loser.

My assertion is this: "If a DBA creates an index, he has a basis for his
actions."

What about a GUC parameter

prefer_indexes = yes/no

Which when set to yes, assumes the DBA knows what he's doing. Unless the
table is really small, in which case it'll still scan.

But then again, if the dba sets up a huge table (million rows) and does a
select over an indexed field that will return 1/6 of all the rows, then
postgres would be nuts to use the index...

But then if the DBA does a query to return just 1 of the rows, postgres
would be nuts NOT to use the index. How do you handle this situation?

Chris

#21Luis Alberto Amigo Navarro
lamigo@atc.unican.es
In reply to: Bruce Momjian (#10)
#22Michael Loftis
mloftis@wgops.com
In reply to: Bruce Momjian (#10)
#23Michael Loftis
mloftis@wgops.com
In reply to: Bruce Momjian (#10)
#24Jean-Paul ARGUDO
jean-paul.argudo@idealx.com
In reply to: mlw (#15)
#25Tycho Fruru
tycho@fruru.com
In reply to: Bruce Momjian (#10)
#26Thomas Lockhart
thomas@fourpalms.org
In reply to: Tycho Fruru (#25)
#27Louis-David Mitterrand
vindex@apartia.org
In reply to: Tom Lane (#9)
#28Tom Lane
tgl@sss.pgh.pa.us
In reply to: mlw (#15)
#29Michael Loftis
mloftis@wgops.com
In reply to: Christopher Kings-Lynne (#13)
#30Michael Loftis
mloftis@wgops.com
In reply to: Christopher Kings-Lynne (#13)
#31Thomas Lockhart
thomas@fourpalms.org
In reply to: Bruce Momjian (#10)
#32Michael Loftis
mloftis@wgops.com
In reply to: Bruce Momjian (#10)
#33mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
#34Thomas Lockhart
thomas@fourpalms.org
In reply to: Christopher Kings-Lynne (#13)
#35Tom Lane
tgl@sss.pgh.pa.us
In reply to: Louis-David Mitterrand (#27)
#36Thomas Lockhart
thomas@fourpalms.org
In reply to: Bruce Momjian (#10)
#37Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Bruce Momjian (#10)
#38mlw
markw@mohawksoft.com
In reply to: Christopher Kings-Lynne (#13)
#39Lincoln Yeoh
lyeoh@pop.jaring.my
In reply to: Thomas Lockhart (#31)
#40Thomas Lockhart
thomas@fourpalms.org
In reply to: Bruce Momjian (#10)
#41Michael Loftis
mloftis@wgops.com
In reply to: Bruce Momjian (#10)
#42Tom Lane
tgl@sss.pgh.pa.us
In reply to: Luis Alberto Amigo Navarro (#21)
#43mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
#44Louis-David Mitterrand
vindex@apartia.org
In reply to: Tom Lane (#35)
#45Mike Mascari
mascarm@mascari.com
In reply to: Christopher Kings-Lynne (#13)
#46Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas Lockhart (#34)
#47Tom Lane
tgl@sss.pgh.pa.us
In reply to: mlw (#43)
#48Tom Lane
tgl@sss.pgh.pa.us
In reply to: Louis-David Mitterrand (#44)
#49mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
#50Hannu Krosing
hannu@tm.ee
In reply to: Tom Lane (#42)
#51Hannu Krosing
hannu@tm.ee
In reply to: Hannu Krosing (#50)
#52Tom Lane
tgl@sss.pgh.pa.us
In reply to: Hannu Krosing (#51)
#53Tom Lane
tgl@sss.pgh.pa.us
In reply to: mlw (#49)
#54mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
#55Andrew Sullivan
andrew@libertyrms.info
In reply to: mlw (#49)
#56Peter Eisentraut
peter_e@gmx.net
In reply to: mlw (#54)
#57mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
#58mlw
markw@mohawksoft.com
In reply to: Peter Eisentraut (#56)
#59Rod Taylor
rbt@rbt.ca
In reply to: Bruce Momjian (#10)
#60Hannu Krosing
hannu@tm.ee
In reply to: Tom Lane (#52)
#61mlw
markw@mohawksoft.com
In reply to: mlw (#11)
#62Andrew Sullivan
andrew@libertyrms.info
In reply to: mlw (#61)
#63Bruce Momjian
bruce@momjian.us
In reply to: mlw (#61)
#64mlw
markw@mohawksoft.com
In reply to: mlw (#14)
#65Bruce Momjian
bruce@momjian.us
In reply to: mlw (#64)
#66mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#63)
#67Bruce Momjian
bruce@momjian.us
In reply to: mlw (#66)
#68Bruce Momjian
bruce@momjian.us
In reply to: Michael Loftis (#32)
#69mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#63)
#70Bruce Momjian
bruce@momjian.us
In reply to: mlw (#69)
#71Doug McNaught
doug@wireboard.com
In reply to: Bruce Momjian (#63)
#72mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#67)
#73D'Arcy J.M. Cain
darcy@druid.net
In reply to: mlw (#69)
#74mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#70)
#75Dann Corbit
DCorbit@connx.com
In reply to: mlw (#74)
#76Bruce Momjian
bruce@momjian.us
In reply to: mlw (#74)
#77Bruce Momjian
bruce@momjian.us
In reply to: D'Arcy J.M. Cain (#73)
#78Bill Cunningham
billc@ballydev.com
In reply to: Bruce Momjian (#10)
#79Sean Chittenden
sean@chittenden.org
In reply to: Tom Lane (#53)
#80Mark Pritchard
mark@tangent.net.au
In reply to: Tom Lane (#42)
#81Mark Pritchard
mark.pritchard@tangent.net.au
In reply to: Mark Pritchard (#80)
#82Thomas Lockhart
lockhart@fourpalms.org
In reply to: Christopher Kings-Lynne (#13)
#83Justin Clift
justin@postgresql.org
In reply to: Christopher Kings-Lynne (#13)
#84Thomas Lockhart
lockhart@fourpalms.org
In reply to: Christopher Kings-Lynne (#13)
#85Justin Clift
justin@postgresql.org
In reply to: Christopher Kings-Lynne (#13)
#86Tom Lane
tgl@sss.pgh.pa.us
In reply to: mlw (#61)
#87mlw
markw@mohawksoft.com
In reply to: mlw (#11)
#88Tom Lane
tgl@sss.pgh.pa.us
In reply to: mlw (#87)
#89Luis Alberto Amigo Navarro
lamigo@atc.unican.es
In reply to: Bruce Momjian (#10)
#90Maarten Boekhold
Maarten.Boekhold@reuters.com
In reply to: Luis Alberto Amigo Navarro (#89)
#91Adrian von Bidder
avbidder@fortytwo.ch
In reply to: Tom Lane (#52)
#92Tycho Fruru
tycho@fruru.com
In reply to: Maarten Boekhold (#90)
#93mlw
markw@mohawksoft.com
In reply to: mlw (#11)
#94Bruce Momjian
bruce@momjian.us
In reply to: mlw (#87)
#95Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#88)
#96mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#10)
#97Michael Loftis
mloftis@wgops.com
In reply to: Bruce Momjian (#63)
#98Michael Loftis
mloftis@wgops.com
In reply to: Bruce Momjian (#10)
#99mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#94)
#100Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Loftis (#98)
#101Thomas Lockhart
lockhart@fourpalms.org
In reply to: Bruce Momjian (#94)
#102Bruce Momjian
bruce@momjian.us
In reply to: mlw (#99)
#103Tom Lane
tgl@sss.pgh.pa.us
In reply to: mlw (#99)
#104Michael Loftis
mloftis@wgops.com
In reply to: Bruce Momjian (#10)
#105Mark Pritchard
mark@tangent.net.au
In reply to: Tom Lane (#100)
#106Michael Loftis
mloftis@wgops.com
In reply to: Bruce Momjian (#10)
#107Curt Sampson
cjs@cynic.net
In reply to: mlw (#96)
#108Curt Sampson
cjs@cynic.net
In reply to: Michael Loftis (#97)
#109Maarten Boekhold
Maarten.Boekhold@reuters.com
In reply to: Curt Sampson (#108)
#110Lincoln Yeoh
lyeoh@pop.jaring.my
In reply to: mlw (#99)
#111Tom Lane
tgl@sss.pgh.pa.us
In reply to: Lincoln Yeoh (#110)
#112Luis Alberto Amigo Navarro
lamigo@atc.unican.es
In reply to: Bruce Momjian (#94)
#113Luis Alberto Amigo Navarro
lamigo@atc.unican.es
In reply to: Bruce Momjian (#94)
#114Bruce Momjian
bruce@momjian.us
In reply to: Lincoln Yeoh (#110)
#115Bruce Momjian
bruce@momjian.us
In reply to: Luis Alberto Amigo Navarro (#112)
#116mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#94)
#117mlw
markw@mohawksoft.com
In reply to: Curt Sampson (#108)
#118Curt Sampson
cjs@cynic.net
In reply to: mlw (#117)
#119Lincoln Yeoh
lyeoh@pop.jaring.my
In reply to: Bruce Momjian (#114)
#120Curt Sampson
cjs@cynic.net
In reply to: Lincoln Yeoh (#119)
#121mlw
markw@mohawksoft.com
In reply to: Curt Sampson (#118)
#122Bruce Momjian
bruce@momjian.us
In reply to: Curt Sampson (#120)
#123Luis Alberto Amigo Navarro
lamigo@atc.unican.es
In reply to: Bruce Momjian (#115)
#124Curt Sampson
cjs@cynic.net
In reply to: Bruce Momjian (#122)
#125Bruce Momjian
bruce@momjian.us
In reply to: Curt Sampson (#124)
#126Curt Sampson
cjs@cynic.net
In reply to: Bruce Momjian (#125)
#127Tom Lane
tgl@sss.pgh.pa.us
In reply to: Curt Sampson (#126)
#128Tatsuo Ishii
t-ishii@sra.co.jp
In reply to: Tom Lane (#127)
#129Bruce Momjian
bruce@momjian.us
In reply to: Curt Sampson (#126)
#130Curt Sampson
cjs@cynic.net
In reply to: mlw (#121)
#131Michael Loftis
mloftis@wgops.com
In reply to: Curt Sampson (#126)
#132Michael Loftis
mloftis@wgops.com
In reply to: Curt Sampson (#130)
#133Curt Sampson
cjs@cynic.net
In reply to: Michael Loftis (#132)
#134Curt Sampson
cjs@cynic.net
In reply to: Tom Lane (#127)
#135Curt Sampson
cjs@cynic.net
In reply to: Bruce Momjian (#129)
#136Lincoln Yeoh
lyeoh@pop.jaring.my
In reply to: Curt Sampson (#126)
#137Curt Sampson
cjs@cynic.net
In reply to: Curt Sampson (#134)
#138Curt Sampson
cjs@cynic.net
In reply to: Lincoln Yeoh (#136)
#139Tom Lane
tgl@sss.pgh.pa.us
In reply to: Curt Sampson (#134)
#140Bruce Momjian
bruce@momjian.us
In reply to: Curt Sampson (#134)
#141Bruce Momjian
bruce@momjian.us
In reply to: Michael Loftis (#132)
#142Bruce Momjian
bruce@momjian.us
In reply to: Curt Sampson (#133)
In reply to: Curt Sampson (#138)
#144mlw
markw@mohawksoft.com
In reply to: Bruce Momjian (#142)
#145Kyle
kaf@nwlink.com
In reply to: Tom Lane (#139)
#146Bruce Momjian
bruce@momjian.us
In reply to: Kyle (#145)
#147Curt Sampson
cjs@cynic.net
In reply to: Tom Lane (#139)
#148Curt Sampson
cjs@cynic.net
In reply to: Bruce Momjian (#141)
#149Curt Sampson
cjs@cynic.net
In reply to: Bruce Momjian (#142)
#150Bruce Momjian
bruce@momjian.us
In reply to: Curt Sampson (#149)
#151Curt Sampson
cjs@cynic.net
In reply to: Bruce Momjian (#150)
#152Tom Lane
tgl@sss.pgh.pa.us
In reply to: Curt Sampson (#151)
#153Curt Sampson
cjs@cynic.net
In reply to: Tom Lane (#152)
#154J. R. Nield
jrnield@usol.com
In reply to: Bruce Momjian (#150)
#155Bruce Momjian
bruce@momjian.us
In reply to: J. R. Nield (#154)
#156J. R. Nield
jrnield@usol.com
In reply to: Bruce Momjian (#155)
#157Curt Sampson
cjs@cynic.net
In reply to: J. R. Nield (#156)
#158Tom Lane
tgl@sss.pgh.pa.us
In reply to: Curt Sampson (#157)
#159Curt Sampson
cjs@cynic.net
In reply to: Tom Lane (#158)
#160J. R. Nield
jrnield@usol.com
In reply to: Tom Lane (#158)
#161Curt Sampson
cjs@cynic.net
In reply to: J. R. Nield (#160)
#162J. R. Nield
jrnield@usol.com
In reply to: Curt Sampson (#159)
#163Bruce Momjian
bruce@momjian.us
In reply to: J. R. Nield (#160)
#164Bruce Momjian
bruce@momjian.us
In reply to: Curt Sampson (#161)
#165Curt Sampson
cjs@cynic.net
In reply to: Bruce Momjian (#164)
#166Dave Cramer
pg@fastcrypt.com
In reply to: Curt Sampson (#161)
#167J. R. Nield
jrnield@usol.com
In reply to: Bruce Momjian (#164)
#168J. R. Nield
jrnield@usol.com
In reply to: J. R. Nield (#167)
#169Bruce Momjian
bruce@momjian.us
In reply to: J. R. Nield (#167)
#170Curt Sampson
cjs@cynic.net
In reply to: J. R. Nield (#167)
#171The Hermit Hacker
scrappy@hub.org
In reply to: Dave Cramer (#166)
#172Tom Lane
tgl@sss.pgh.pa.us
In reply to: Curt Sampson (#165)
#173Dave Page
dpage@pgadmin.org
In reply to: The Hermit Hacker (#171)
#174Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#172)
#175Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#174)
#176J. R. Nield
jrnield@usol.com
In reply to: Curt Sampson (#170)
#177Tom Lane
tgl@sss.pgh.pa.us
In reply to: J. R. Nield (#176)
#178Bruce Momjian
bruce@momjian.us
In reply to: J. R. Nield (#176)
#179Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#178)
#180Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#179)
#181J. R. Nield
jrnield@usol.com
In reply to: Tom Lane (#177)
#182Curt Sampson
cjs@cynic.net
In reply to: J. R. Nield (#176)
#183Curt Sampson
cjs@cynic.net
In reply to: J. R. Nield (#176)
#184Curt Sampson
cjs@cynic.net
In reply to: Tom Lane (#177)
#185Bruce Momjian
bruce@momjian.us
In reply to: Curt Sampson (#184)
#186Curt Sampson
cjs@cynic.net
In reply to: Curt Sampson (#183)
#187Tom Lane
tgl@sss.pgh.pa.us
In reply to: Curt Sampson (#186)
#188Larry Rosenman
ler@lerctr.org
In reply to: Tom Lane (#187)
#189Curt Sampson
cjs@cynic.net
In reply to: Tom Lane (#187)
#190Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#187)
#191Lee Kindness
lkindness@csl.co.uk
In reply to: Tom Lane (#187)
#192Curt Sampson
cjs@cynic.net
In reply to: Bruce Momjian (#190)
#193Tom Lane
tgl@sss.pgh.pa.us
In reply to: Curt Sampson (#189)
#194Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#190)
#195Mario Weilguni
mario.weilguni@icomedias.com
In reply to: Tom Lane (#194)
#196Tom Lane
tgl@sss.pgh.pa.us
In reply to: Mario Weilguni (#195)
#197Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#194)
#198Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#193)
#199Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#198)
#200Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#199)
#201Bradley McLean
brad@bradm.net
In reply to: Tom Lane (#196)
#202Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bradley McLean (#201)
#203Curt Sampson
cjs@cynic.net
In reply to: Tom Lane (#193)
#204Tom Lane
tgl@sss.pgh.pa.us
In reply to: Curt Sampson (#203)
#205Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#204)
#206Curt Sampson
cjs@cynic.net
In reply to: Tom Lane (#204)