Slow join on otherwise fast views?

This is a discussion on Slow join on otherwise fast views? within the MySQL Database forums, part of the Database Forums category; If select * from vw_fielddata takes 16ms to return just four rows, why does select * from vw_fielddata firstname join vw_fielddata secondname ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-05-2008
Shak
 
Posts: n/a
Default Slow join on otherwise fast views?

If

select * from vw_fielddata

takes 16ms to return just four rows, why does

select
*
from
vw_fielddata firstname
join
vw_fielddata secondname
on
secondname.AccountID = firstname.AccountID

take over an hour? The views themselves contain joins on tables and further
views, and although AccountID isn't a primary key from the tables it's
gathered from it is a foreign key in them (I assume this makes it indexed?).

Suggestions for diagnosing/optimising? The tables are tiny and the order of
time taken so large, so I don't believe it's an optimisation issue.

Shak

Reply With Quote
  #2 (permalink)  
Old 07-05-2008
Shak
 
Posts: n/a
Default Re: Slow join on otherwise fast views?

"Shak" <Shak@shak.com> wrote in message
news:g4nu4c$4pq$1@registered.motzarella.org...
> If
>
> select * from vw_fielddata
>
> takes 16ms to return just four rows, why does
>
> select
> *
> from
> vw_fielddata firstname
> join
> vw_fielddata secondname
> on
> secondname.AccountID = firstname.AccountID
>
> take over an hour? The views themselves contain joins on tables and
> further views, and although AccountID isn't a primary key from the tables
> it's gathered from it is a foreign key in them (I assume this makes it
> indexed?).
>
> Suggestions for diagnosing/optimising? The tables are tiny and the order
> of time taken so large, so I don't believe it's an optimisation issue.
>


It seems that my query is stuck in the "statistics" state. Reading up, it
seems that the optimiser may be looking for the best way to do the many
joins within the views. Is there any way of forcing it to just pick one
early?

Shak

Reply With Quote
  #3 (permalink)  
Old 07-06-2008
ThanksButNo
 
Posts: n/a
Default Re: Slow join on otherwise fast views?

On Jul 5, 8:58 am, "Shak" <S...@shak.com> wrote:
> "Shak" <S...@shak.com> wrote in message
>
> news:g4nu4c$4pq$1@registered.motzarella.org...
>
>
>
> > If

>
> > select * from vw_fielddata

>
> > takes 16ms to return just four rows, why does

>
> > select
> > *
> > from
> > vw_fielddata firstname
> > join
> > vw_fielddata secondname
> > on
> > secondname.AccountID = firstname.AccountID

>
> > take over an hour? The views themselves contain joins on tables and
> > further views, and although AccountID isn't a primary key from the tables
> > it's gathered from it is a foreign key in them (I assume this makes it
> > indexed?).

>
> > Suggestions for diagnosing/optimising? The tables are tiny and the order
> > of time taken so large, so I don't believe it's an optimisation issue.

>
> It seems that my query is stuck in the "statistics" state. Reading up, it
> seems that the optimiser may be looking for the best way to do the many
> joins within the views. Is there any way of forcing it to just pick one
> early?
>
> Shak


Try to redesign your queries to skip the views, and go straight to the
base tables. Perhaps you can avoid most of the joins that way, by not
trying to retrieve data in tables that you don't need.
Reply With Quote
  #4 (permalink)  
Old 07-07-2008
Shak
 
Posts: n/a
Default Re: Slow join on otherwise fast views?

"ThanksButNo" <no.no.thanks@gmail.com> wrote in message
news:f3593dce-4294-4cd3-9aa7-9f88dd90424a@t54g2000hsg.googlegroups.com...
> On Jul 5, 8:58 am, "Shak" <S...@shak.com> wrote:
>> "Shak" <S...@shak.com> wrote in message
>>
>> news:g4nu4c$4pq$1@registered.motzarella.org...
>>
>>
>>
>> > If

>>
>> > select * from vw_fielddata

>>
>> > takes 16ms to return just four rows, why does

>>
>> > select
>> > *
>> > from
>> > vw_fielddata firstname
>> > join
>> > vw_fielddata secondname
>> > on
>> > secondname.AccountID = firstname.AccountID

>>
>> > take over an hour? The views themselves contain joins on tables and
>> > further views, and although AccountID isn't a primary key from the
>> > tables
>> > it's gathered from it is a foreign key in them (I assume this makes it
>> > indexed?).

>>
>> > Suggestions for diagnosing/optimising? The tables are tiny and the
>> > order
>> > of time taken so large, so I don't believe it's an optimisation issue.

>>
>> It seems that my query is stuck in the "statistics" state. Reading up, it
>> seems that the optimiser may be looking for the best way to do the many
>> joins within the views. Is there any way of forcing it to just pick one
>> early?
>>
>> Shak

>
> Try to redesign your queries to skip the views, and go straight to the
> base tables. Perhaps you can avoid most of the joins that way, by not
> trying to retrieve data in tables that you don't need.



But I'm trying to stick to a particular design. I've figured out how to
adjust the optimiser though - setting OPTIMIZER_SEARCH_DEPTH to something a
bit less insane than its default of 62 helped, and the query is now pretty
much instant.

Shak

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0