Here is my setup:
Windows Server 2008 R2 MySql 5.1.562 Php 5.3.2 Doctrine 1.2Anybody have an Idea why my query is taking about one second to perform a simple query.
echo date("Y-m-d H:i:s", time()) ."::::::" . microtime(true)."<br />";
$q = Doctrine_Query::create()
->from("Ordering")
->where("client_id = ?",array($_SESSION["UserID"]));
$ResProduct = $q->execute();
echo date("Y-m-d H:i:s", time()) ."::::::" . microtime(true)."<br />";
Here is the result of the 2 echo to show you how long it's take to perform the query.
2011-04-21 01:48:24::::::1303364904.805开发者_如何学Python1
2011-04-21 01:48:25::::::1303364905.8418
An other thing, there is no data in the database.
Edit
I Perform the query directly in the mysql console and get the result very quicklymysql> select * from Ordering where client_id = 2;
+----+------------+-------+------+-----------+
| id | product_id | price | qty | client_id |
+----+------------+-------+------+-----------+
| 7 | 1 | 0.89 | 20 | 2 |
+----+------------+-------+------+-----------+
1 row in set (0.00 sec)
- Use
microtime(true)
instead ofmicrotime_float()
- Configure MySQL not to resolve IP's of connecting clients: http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_skip-name-resolve
client_id = ?
- why do you cast$_SESSION["UserID"]
to array? I think this is unnecessary.
First of all, your code doesn't seem wrong or anything.
Basically, though, your SQL query will typically look like this :
select *
from Ordering
where client_id = 123456
Which means that setting an index on the client_id
column should probably help -- a lot, if there are many rows in that table.
A couple of relevant links, about that :
CREATE INDEX
Syntax- How MySQL Uses Indexes
Just out of curiosity have you attempted a RawSQL Query? We had an issue similar to this and it ended up being a DNS issue. Even though everything was supposed to be localhost the apache server was going external to resolve the address to mysql for some reason.
精彩评论