Subject | Re: Performance decrease after running SET INDEX STATISTICS |
---|---|
Author | accdev3234 |
Post date | 2009-03-31T03:44:49Z |
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@...>
wrote:
SQL> SELECT DISTINCT BR.BASE_SN, R.TITLE
CON> FROM RES R
CON> JOIN BASERES BR ON BR.BASE_SN = R.BASE_SN AND
CON> BR.BASE_SN IN
(8,71,99,130,310,356,426,529,537,689,19736,19792,19917,19929,20089,20094\
,20108,20110,20115,20191) AND BR.STATUS=1
CON> WHERE
CON> R.STATUS=1;
PLAN JOIN (R NATURAL,BR INDEX
(PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BA\
SERES,PK_BASERES,PK_BASERES,PK_BASERES,
PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BAS\
ERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES))
SQL>
SQL> SELECT DISTINCT BR.BASE_SN, R.TITLE
CON> FROM RES R
CON> JOIN BASERES BR ON BR.BASE_SN = R.BASE_SN
CON> WHERE
CON> R.STATUS=1 AND BR.STATUS=1 AND
CON> BR.BASE_SN IN
(8,71,99,130,310,356,426,529,537,689,19736,19792,19917,19929,20089,20094\
,20108,20110,20115,20191);
PLAN SORT (JOIN (R NATURAL,BR INDEX
(PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BA\
SERES,PK_BASERES,PK_BASERES,PK_BASERES,
PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BAS\
ERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES)))
of the BASERES table.
difference and it doesn't.
statistics then the performance drops.
tested from other sites,
is using both IBExpert and isql.
You might get more direct info about what the *optimizer* is doing by
using isql for those tests. AFAIK, IBExpert fiddles about with plans
according to its own rules and could well defeat better choices made by
the optimizer.
benefits you have accumulated from the cache.
to try out GROUP BY for the sort instead and see if it improves things,
viz.
isql for this kind of thing: you probably shun it because it is so
"bare-bones", but when "bare-bones" is what you really need, it's worth
the effort !
IBExpert. Will now get to to know isql more.
If I change the alias in the where clause (change BR.BASE_SN to
R.BASE_SN):
SQL> SELECT DISTINCT BR.BASE_SN, R.TITLE
CON> FROM RES R
CON> JOIN BASERES BR ON R.BASE_SN = BR.BASE_SN
CON> WHERE
CON> R.STATUS = 1 AND BR.STATUS = 1 AND
CON> R.BASE_SN IN
(8,71,99,130,310,356,426,529,537,689,19736,19792,19917,19929,20089,20094\
,20108,20110,20115,20191);
PLAN SORT (JOIN (R INDEX
(FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE\
_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,
FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_\
REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,
FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_\
REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,
FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_\
REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,
FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_\
REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO),
BR INDEX (PK_BASERES)))
This is fast for this database but slow for others I tested against.
Maybe it is time to revisit the full query against the other databases
and see if they can be improved.
Thanks.
wrote:
>down dramatically after we call SET INDEX STATISTICS.
> At 11:54 AM 28/03/2009, you wrote:
> >We have a strange scenario at one of our sites where one query slows
> >Unfortunately this is used a lot so it causing performance issuesthroughout the system.
> >SQL> SET PLANONLY;
> >The basic query is:
> >
> > SELECT DISTINCT BR.BASE_SN, R.TITLE
> > FROM RES R
> > JOIN BASERES BR ON BR.BASE_SN = R.BASE_SN
> > WHERE R.STATUS=1 AND BR.STATUS=1 AND
> > BR.BASE_SN IN (<insert list of primary keys>)
>
> Try this:
> SELECT DISTINCT BR.BASE_SN, R.TITLE
> FROM RES R
> JOIN BASERES BR ON BR.BASE_SN = R.BASE_SN
> AND BR.BASE_SN IN (<insert list of primary keys>)
> AND BR.STATUS=1
>
> WHERE R.STATUS=1
>
> and give the plans for both versions.
>
SQL> SELECT DISTINCT BR.BASE_SN, R.TITLE
CON> FROM RES R
CON> JOIN BASERES BR ON BR.BASE_SN = R.BASE_SN AND
CON> BR.BASE_SN IN
(8,71,99,130,310,356,426,529,537,689,19736,19792,19917,19929,20089,20094\
,20108,20110,20115,20191) AND BR.STATUS=1
CON> WHERE
CON> R.STATUS=1;
PLAN JOIN (R NATURAL,BR INDEX
(PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BA\
SERES,PK_BASERES,PK_BASERES,PK_BASERES,
PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BAS\
ERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES))
SQL>
SQL> SELECT DISTINCT BR.BASE_SN, R.TITLE
CON> FROM RES R
CON> JOIN BASERES BR ON BR.BASE_SN = R.BASE_SN
CON> WHERE
CON> R.STATUS=1 AND BR.STATUS=1 AND
CON> BR.BASE_SN IN
(8,71,99,130,310,356,426,529,537,689,19736,19792,19917,19929,20089,20094\
,20108,20110,20115,20191);
PLAN SORT (JOIN (R NATURAL,BR INDEX
(PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BA\
SERES,PK_BASERES,PK_BASERES,PK_BASERES,
PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BAS\
ERES,PK_BASERES,PK_BASERES,PK_BASERES,PK_BASERES)))
> >FK constraint R.BASE_SN -> BR.BASE_SN and BR.BASE_SN is the primary key
> >Both the BASERES and RES tables have about 25000 records. There is a
of the BASERES table.
> >The status columns are not indexed as there are only 2 distinctvalues. However, I did try adding an index to see if that makes any
difference and it doesn't.
>after exporting and importing the data. Then, if we update the index
> No, it would make things worse in v.1.5.x.
>
>
> >For all our other sites this is not a problem and this site runs ok
statistics then the performance drops.
> >For them, the query take 90secs but after export/import, the querytakes about 6secs. This returns just 334 records.
> >keys>) then the query is again fast. Unfortunately, for all other DBs
> >If we change the WHERE to R.BASE_SN IN (<insert list of primary
tested from other sites,
> >the performance is worse when we change the alias.running the same query a second time is just as slow.
> >
> >Using the clients database, it is easy to replicate.
> >
> >1. Load IBExpert and run query (fast)
> >2. Recalculate index statistics in IBExpert
> >3. Run query again - now slow.
>
> It's more than likely something to do with the caching. Test whether
>Running the queries for a second time still gives the same timing. This
is using both IBExpert and isql.
> For your own edification, you could get some clues about theusefulness (or not) of various approaches if you studied the plans used.
You might get more direct info about what the *optimizer* is doing by
using isql for those tests. AFAIK, IBExpert fiddles about with plans
according to its own rules and could well defeat better choices made by
the optimizer.
>database.
>
> >Basically fbserver gets locked at 100% CPU and noone else can use the
> >This is using FB SS 1.5.5 on Windows and Linux.necessarily doing you any favours since it necessarily blows away any
> >
> >Any thoughts as how we can resolve this issue?
>
> For one thing, I don't think doing SET STATISTICS on the fly is
benefits you have accumulated from the cache.
>and below) because it can't use an index at sort time. You might like
> For another, SELECT DISTINCT is a performance killer (esp. in v.1.5
to try out GROUP BY for the sort instead and see if it improves things,
viz.
>No difference.
> Try this:
> SELECT BR.BASE_SN, R.TITLE
> FROM RES R
> JOIN BASERES BR ON BR.BASE_SN = R.BASE_SN
> AND BR.BASE_SN IN (<insert list of primary keys>)
> AND BR.STATUS=1
> WHERE R.STATUS=1
> GROUP BY 1,2
>
> And, finally, for performance testing I'd stay away from elaboratetools that do fancy things with your query specs. Get familiar with
isql for this kind of thing: you probably shun it because it is so
"bare-bones", but when "bare-bones" is what you really need, it's worth
the effort !
>Don't mind the "bare-bones" approach, just currently more familiar with
> ./heLen
>
IBExpert. Will now get to to know isql more.
If I change the alias in the where clause (change BR.BASE_SN to
R.BASE_SN):
SQL> SELECT DISTINCT BR.BASE_SN, R.TITLE
CON> FROM RES R
CON> JOIN BASERES BR ON R.BASE_SN = BR.BASE_SN
CON> WHERE
CON> R.STATUS = 1 AND BR.STATUS = 1 AND
CON> R.BASE_SN IN
(8,71,99,130,310,356,426,529,537,689,19736,19792,19917,19929,20089,20094\
,20108,20110,20115,20191);
PLAN SORT (JOIN (R INDEX
(FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE\
_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,
FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_\
REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,
FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_\
REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,
FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_\
REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,
FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO,FK_RESOURCE_\
REF_2064_BASERESO,FK_RESOURCE_REF_2064_BASERESO),
BR INDEX (PK_BASERES)))
This is fast for this database but slow for others I tested against.
Maybe it is time to revisit the full query against the other databases
and see if they can be improved.
Thanks.