🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #5

Re: Problem with index

#5
From: Cyber Sinh
Date: Thu, 21 Jul 2005 10:10
79 lines
3736 bytes
Cyber Sinh a �crit :
> Hi,
> 
> Why the first query don't use index on T_TRACK (take 15 s!) whereas the 
> second use it (and take only 0s!)?
> 
> PS: I use Firebird 1.5
> 
> SELECT t_album.c_id, t_album.c_artist, t_album.c_name
> FROM t_album
> INNER JOIN t_albumjoin ON t_albumjoin.c_album = t_album.c_id
> INNER JOIN t_track ON t_albumjoin.c_track = t_track.c_id
> INNER JOIN t_artist ON t_artist.c_id = t_track.c_artist
> WHERE t_artist.c_name = 'Evanescence';
> 
> 
> Plan
> PLAN JOIN (T_TRACK NATURAL,T_ARTIST INDEX (ARTIST_PKEY),T_ALBUMJOIN 
> INDEX (ALBUMJOIN_FK_TRACK),T_ALBUM INDEX (ALBUM_PKEY))
> 
> Plan Adpat�
> PLAN JOIN (T_TRACK NATURAL,T_ARTIST INDEX (ARTIST_PKEY),T_ALBUMJOIN 
> INDEX (ALBUMJOIN_FK_TRACK),T_ALBUM INDEX (ALBUM_PKEY))
> 
> ------ Performance info ------
> Prepare time = 0ms
> Execute time = 15s 828ms
> Avg fetch time = 565,29 ms
> Current memory = 1 110 768
> Max memory = 1 244 108
> Memory buffers = 2 048
> Reads from disk to cache = 3 680
> Writes from cache to disk = 0
> Fetches from cache = 5 112 579
> 
> 
> 
> SELECT t_album.c_id, t_album.c_artist, t_album.c_name
> FROM t_album
> INNER JOIN t_albumjoin ON t_albumjoin.c_album = t_album.c_id
> INNER JOIN t_track ON t_albumjoin.c_track = t_track.c_id
> INNER JOIN t_artist ON t_artist.c_id = t_track.c_artist
> WHERE t_artist.c_name = 'Evanescence' AND
> t_track.c_name = 'Anywhere' AND
> t_album.c_name = 'Origin';
> 
> 
> Plan
> PLAN JOIN (T_TRACK INDEX (TRACK_NAME),T_ARTIST INDEX 
> (ARTIST_PKEY),T_ALBUM INDEX (ALBUM_NAME),T_ALBUMJOIN INDEX 
> (ALBUMJOIN_FK_TRACK,ALBUMJOIN_FK_ALBUM))
> 
> Plan Adpat�
> PLAN JOIN (T_TRACK INDEX (TRACK_NAME),T_ARTIST INDEX 
> (ARTIST_PKEY),T_ALBUM INDEX (ALBUM_NAME),T_ALBUMJOIN INDEX 
> (ALBUMJOIN_FK_TRACK,ALBUMJOIN_FK_ALBUM))
> 
> ------ Performance info ------
> Prepare time = 0ms
> Execute time = 0ms
> Avg fetch time = 0,00 ms
> Current memory = 1 128 940
> Max memory = 1 244 108
> Memory buffers = 2 048
> Reads from disk to cache = 0
> Writes from cache to disk = 0
> Fetches from cache = 783
> 
> 
> Thanks for your help...
> Cyber Sinh
Je pense que la baisse de performance est simplement du � la diff�rence 
de la requete. Dans la premi�re, j'utilise une clause WHERE 
suppl�mentaire qui permet au moteur de disqualifier d'office un grand 
nombre d'enregistrements ! Dans la seconde requete, le moteur est oblig� 
de parcourir tous les enregistrements de la table (plus de 3 000 000)...

Le probl�me, c'est que je ne sais pas comment mieux optimiser ma requ�te 
(tous les champs de tri / filtrage contiennent des index). Une id�e ?
Technical Details
Message-ID: <42df739f$0$12776$636a15ce@news.free.fr>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-2.proxad.net!news14-e.free.fr!not-for-mail
References: <42dcf727$0$1453$626a14ce@news.free.fr>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,d46142938748c3f7
X-Google-Thread: fd38c,d46142938748c3f7
X-Google-Attributes: gid114a0e,gidfd38c,public
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-2.proxad.net!news14-e.free.fr!not-for-mail
Date: Thu, 21 Jul 2005 12:10:24 +0200
From: Cyber Sinh <cyber.sinh@-moins.ceci-free.fr>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: fr, en
MIME-Version: 1.0
Newsgroups: borland.public.interbase.sql,borland.public.interbase.general
Subject: Re: Problem with index
References: <42dcf727$0$1453$626a14ce@news.free.fr>
In-Reply-To: <42dcf727$0$1453$626a14ce@news.free.fr>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 79
Message-ID: <42df739f$0$12776$636a15ce@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 21 Jul 2005 12:06:23 MEST
NNTP-Posting-Host: 82.65.127.154
X-Trace: 1121940383 news14-e.free.fr 12776 82.65.127.154:1125
X-Complaints-To: abuse@proxad.net