From: <[EMAIL PROTECTED]>
Subject: Re: more queries vs a bigger one

> Hello,
> approx. how long does it take your "big" query to run as it is now?  Are
> these queries appending a table? or are they buiding a result (from a
> "chain" of queries)?  Have you tried separating them out?  Any difference?
> -sam
>
>

That query takes more than 2 minutes.
I have a table with less than 90.000 records, and this is the bigger table
from the database, so the query is very slow, because as you may see, the
tables are not very big.

But that query might return more than 9.000 records, even though I limit it
to first 30.

I will split it into more smaller queries and I will report if it works
faster.

The query is something like the example below, but I don't have it here
right now to send it to the list, but I will send it soon:

select a.pre_title, a.title, a.post_title, substring(a.body, 1,
n.preview_size) as preview, n.title as publication, a.id_category, cs.label,
count(aco.hash_articles) as comments, count(act.hash_articles) as counter
from articles a
left join newspapers n on(a.id_newspapers=n.id)
left join sections s on(a.id_sections=s.id and s.id_newspapers=n.id)
left join sections_categories cs on(a.id_categories=cs.id)
inner join articles_counters act on(a.body_hash=act.hash_articles)
inner join articles_comments aco on(a.body_hash=aco.hash_articles)
where a.id_category=20
and a.date between '2005-01-01' and '2005-12-31'
group by a.body_hash order by rand();

The table newspapers has only 20 records. The table sections has under 300
records, but the tables articles_counter and articles_comments might have
many records... hundread of thousands.... millions.

Thanks.

Teddy


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to