# Why is this query slow?

**URL:** <https://forums.percona.com/t/why-is-this-query-slow/341>\
**Category:** Other MySQL® Questions\
**Created:** [June 1, 2007, 5:29pm UTC](https://forums.percona.com/t/why-is-this-query-slow/341 "2007-06-01T17:29:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GeoffreyF67](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GeoffreyF67](https://forums.percona.com/u/GeoffreyF67)\
**Post date:** [June 1, 2007, 5:29pm UTC](https://forums.percona.com/t/why-is-this-query-slow/341/1 "2007-06-01T17:29:36Z")

</div>

I have a table with this structure that has 1.3 million rows:

CREATE TABLE `KeywordST` ( `ID` int(10) unsigned NOT NULL, `BNDate` timestamp NOT NULL default CURRENT\_TIMESTAMP on update CURRENT\_TIMESTAMP, `BNCount` int(11) NOT NULL default ‘0’, PRIMARY KEY (`ID`), KEY `BNDate` (`BNDate`,`BNCount`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8\_swedish\_ci;

I did an explain on a query I use to get data:

explain select count(ID) from KeywordST where BNDate \< subtime( now( ) , ‘12:00:00.0’ ) limit 20\G\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 1. row \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* id: 1 select\_type: SIMPLE table: KeywordST type: rangepossible\_keys: BNDate key: BNDate key\_len: 4 ref: NULL rows: 743702 Extra: Using where1 row in set (0.01 sec)

It looks ok to me but I’m sure I’m missing something because this query takes 2.82 seconds to execute!

Any ideas?

Edit: I really only need to know if there will be 20 matches or not…hmmm…ref means it’s doing a full table scan doesn’t it?

---

<div class="post-metadata">

**Author:** ![GeoffreyF67](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GeoffreyF67](https://forums.percona.com/u/GeoffreyF67)\
**Post date:** [June 1, 2007, 11:45pm UTC](https://forums.percona.com/t/why-is-this-query-slow/341/2 "2007-06-01T23:45:04Z")

</div>

Duh…Answered my own question )

All I needed to do was mysql\_num\_rows instead of trying to count(ID) )
