473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

mysql: slow order by query

Can some one help me? I am using mysql 4.0.20a

Here's the situation (I know it sounds kinda strange, but please follow
me here):

I'm trying to create a messaging forum. I have Forums (for example
sports), within those forums, I have topics, for example "Who will win
the World Series." There is another table which contains threads,
within the topics. I also have a hit_counter table which has an
object_id, object_type, and num_hits. I want to sort the results by
num_hits.

So, if I try to do something like this:

SELECT T.title, H.num_hits FROM topics as T, hit_counter as H, threads
as R WHERE T.forum_id=1 AND T.topic_id=R.topic_id AND
H.object_id=R.thread_id AND H.object_type='THREAD'ORDER BY H.num_hits DESC

when I do an EXPLAIN SELECT it tells me:

Using where; Using temporary; Using filesort

which is SLOW.

Here's a short version of what I want to happen:

Topics picked by forum_id
Threads picked by thread.topic_id
hit_counter picked by thread_id AND
The whole thing sorted by hit_counter.num_hits.

Is there a way to do this any faster that doesn't sort a temporary file?
And I already have plenty indexes (I have one on forum_id, topic_id,
num_hits).

-d
Jul 20 '05 #1
1 2037
Hi Doug,

Maybe u should try to limit your query by adding : "LIMIT 0,50" (to
limit only 50 records) so that the data request should be smaller and
there is no more *SLOW* !

I hope it can help you.. :p

God Bless,

Octavianus S

Doug <do*****@XXXXremovetheXearthlink.net> wrote in message news:<0q****************@newsread3.news.atl.earthl ink.net>...
Can some one help me? I am using mysql 4.0.20a

Here's the situation (I know it sounds kinda strange, but please follow
me here):

I'm trying to create a messaging forum. I have Forums (for example
sports), within those forums, I have topics, for example "Who will win
the World Series." There is another table which contains threads,
within the topics. I also have a hit_counter table which has an
object_id, object_type, and num_hits. I want to sort the results by
num_hits.

So, if I try to do something like this:

SELECT T.title, H.num_hits FROM topics as T, hit_counter as H, threads
as R WHERE T.forum_id=1 AND T.topic_id=R.topic_id AND
H.object_id=R.thread_id AND H.object_type='THREAD'ORDER BY H.num_hits DESC

when I do an EXPLAIN SELECT it tells me:

Using where; Using temporary; Using filesort

which is SLOW.

Here's a short version of what I want to happen:

Topics picked by forum_id
Threads picked by thread.topic_id
hit_counter picked by thread_id AND
The whole thing sorted by hit_counter.num_hits.

Is there a way to do this any faster that doesn't sort a temporary file?
And I already have plenty indexes (I have one on forum_id, topic_id,
num_hits).

-d

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: alex | last post by:
Hi. I am making a page that lots of data on the first page that I want links displayed in a random order. If lots of people are looking at it, would I be better using a page that uses arrays and...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
1
by: Gregory.Spencer | last post by:
Hi there, Using PHPMyAdmin and it is very usefully reporting problems with my MySQL DB. "PRIMARY and INDEX keys should not both be set for column `column_name`" and
33
by: Joshua D. Drake | last post by:
Hello, I think the below just about says it all: http://www.commandprompt.com/images/mammoth_versus_dolphin_500.jpg Sincerely, Joshua Drake
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
6
by: Ridge Burner | last post by:
Can someone tell me which of these 2 SQL queries will be more efficient? I'm having a debate with another guy about which would be less resource intensive for MySQL. The first uses MySQL to pick...
1
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname,...
9
by: Derrick Shields | last post by:
I'm working with a database that has over 11 million rows. The .SQL drop file is about 2.5gigs. Doing a simple query: select * from people where last_name like '%smith%' A query like this can...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.