Speeding up SELECT statement

Jan Eden <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <r02010500-1038-4759AE5EA1BD11D9A868000A959B4026@[10.149.23.127]>
Hi,

my setup is the following: I request a number of records from the database and print them out in an unordered HTML list. For each item of a certain type (category), I want to display the number of its "children".

This is what I currently do:

my $query = sprintf("SELECT page_id, title, visible, user_id, position, page_type FROM pages WHERE mother_id = $id ORDER by position, title LIMIT %d,%d", $start-1,$per_page); 
my $sth = $dbh->prepare($query);
$sth->execute();

my $count_query = "SELECT page_id FROM pages WHERE mother_id = ?";
my $count_handle = $dbh->prepare($count_query);

while (my $page = $sth->fetchrow_hashref) {
    my ($rowcount) = $count_handle->execute($page->{page_id}) if $page->{page_type} == 0;
    [...]
}

I need to speed up the execution of the $count_query, as it slows down the display of pages which contain many categories as children.

I tried using SELECT COUNT(*) in the $count_query, but this did not help much.

Is there any way to get the results much quicker?

Thanks,

Jan
-- 
I'd never join any club that would have the likes of me as a member. - Groucho Marx

-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.