# Slow COUNT query that uses a fulltext index

**URL:** <https://forums.percona.com/t/slow-count-query-that-uses-a-fulltext-index/2069>\
**Category:** Sphinx & Full-Text Search\
**Created:** [November 15, 2007, 9:42am UTC](https://forums.percona.com/t/slow-count-query-that-uses-a-fulltext-index/2069 "2007-11-15T09:42:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hammet](https://avatars.discourse-cdn.com/v4/letter/h/9de053/32.png) [@hammet](https://forums.percona.com/u/hammet)\
**Post date:** [November 15, 2007, 9:42am UTC](https://forums.percona.com/t/slow-count-query-that-uses-a-fulltext-index/2069/1 "2007-11-15T09:42:16Z")

</div>

Hi,

I have a slow count(\*) query that uses a fulltext index and i can’t find out why execution time is so awful. The query as it  
stands takes about ~2-5 sec to execute, depends of found rows quantity.

Here’s the query:

SELECT COUNT(\*) AS foundFROM `t1` WHERE MATCH (fullsearch) AGAINST (‘+объявлен’ IN BOOLEAN MODE)

later i’ve found that this query goes faster:

SELECT COUNT(MATCH (fullsearch) AGAINST (‘+объявлен’ IN BOOLEAN MODE)) AS foundFROM `t1` WHERE MATCH (fullsearch) AGAINST (‘+объявлен’ IN BOOLEAN MODE)

the results are follow:  
Found 161354 of 322271 rows.  
Execution time: 3.4158 sec.

Here is EXPLAIN:  
id: 1  
select\_type: SIMPLE  
table: t1  
type: fulltext  
possible\_keys: fullsearch  
key: fullsearch  
key\_len: 0  
ref:  
rows: 1  
Extra: Using where

What can i do to count found rows? is there any suggestion that can be applied to speed this up?

Any insight would be appreciated!

---

<div class="post-metadata">

**Author:** ![awadhaj](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@awadhaj](https://forums.percona.com/u/awadhaj)\
**Post date:** [December 3, 2007, 2:45am UTC](https://forums.percona.com/t/slow-count-query-that-uses-a-fulltext-index/2069/2 "2007-12-03T02:45:03Z")

</div>

i think the two-steps query below is much faster;  
at least it will ommit one of your two ft scans.

SELECT SQL\_CALC\_FOUND\_ROWS id  
FROM `t1` WHERE MATCH (fullsearch)  
AGAINST (‘+объявлен’ IN BOOLEAN MODE)

SELECT FOUND\_ROWS AS found

where id is your pk or an indexed field
