count performance

Post Reply
gaurav.shetti
Posts: 119
Joined: Fri Feb 27, 2009 9:09 am

count performance

Post by gaurav.shetti »

I am running a query which is of the is form

select count(*) from doc_id where x=10 and b in (1,2,3,4 .... upto 50 entries) and query like abc

the count is taking too much time to return. it takes about 2000 seconds to return the count

If i remove the count and print docids it is done very fast. A binary index exists on doc_id.

I also tried
select count(doc_id) from doc_id where x=10 and b in (1,2,3,4 .... upto 50 entries) and query like abc

still the same old story.

Any suggestions to improve the performance.

There are about million documents that match the query and are satisfied by the above sql condition
User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

count performance

Post by John »

We'd need more information to know for sure. Which indices do you have? When you say selecting records is fast, is that to select all, or just the first few?
John Turnbull
Thunderstone Software
gaurav.shetti
Posts: 119
Joined: Fri Feb 27, 2009 9:09 am

count performance

Post by gaurav.shetti »

xdocid group_profile xdocid A B 01 doc_id

This is from the SYSINDEX table.

And I am actaully putting the print statement within sql
<sql> print </sql>

and breaking the loop after 15 records. So you can say i am outputting a few records.
User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

count performance

Post by John »

It sounds as if you probably do not have indexes that can resolve the entire query, so it needs to read in all potentially matching rows to evaluate the entire where clause to see how many actually match.

You could either create appropriate indexes, or after you've selected 15 to display look at $indexcount or $rows.min and $rows.max to get an estimate of number of matches if you do not need a precise count.
John Turnbull
Thunderstone Software
gaurav.shetti
Posts: 119
Joined: Fri Feb 27, 2009 9:09 am

count performance

Post by gaurav.shetti »

Can you explain the last line with an example
User avatar
mark
Site Admin
Posts: 5514
Joined: Tue Apr 25, 2000 6:56 pm

count performance

Post by mark »

User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

count performance

Post by John »

<sql max=15 $sql>
<print>
</sql>
There are about $indexcount matches (between $rows.min and $rows.max)

The number in $indexcount should be the number of records that matched from the index, before the rest of the where clause is evaluated.
John Turnbull
Thunderstone Software
gaurav.shetti
Posts: 119
Joined: Fri Feb 27, 2009 9:09 am

count performance

Post by gaurav.shetti »

In that case indexcount will be much larger than the actual count. Sometimes multiplied by 10 that huge, as we have many conditions in where clause
Post Reply