Re: [nyphp-talk] Adding indexes

2010-03-23 Thread Adrian Noland
Just in case you need some more information about how to fix your queries, this walks you through some examples http://hackmysql.com/case2 On Mon, Mar 22, 2010 at 10:00 AM, Nicholas Hart wrote: > I am looking to analyze and speed up some of my queries by adding any > necessary indexes. Is there

Re: [nyphp-talk] Adding indexes

2010-03-23 Thread Rob Marscher
On Mar 23, 2010, at 11:50 AM, Daniel Convissor wrote: > On Tue, Mar 23, 2010 at 11:12:57AM -0400, Rob Marscher wrote: >> >> I'm having trouble finding exactly where it says it. > ... >> If you run EXPLAIN, you'll see it only picks one index to use for each >> table. > > That may be true for the

Re: [nyphp-talk] Adding indexes

2010-03-23 Thread Daniel Convissor
On Tue, Mar 23, 2010 at 11:12:57AM -0400, Rob Marscher wrote: > > I'm having trouble finding exactly where it says it. ... > If you run EXPLAIN, you'll see it only picks one index to use for each > table. That may be true for the queries you ran. If that's the case, you don't have enough rows

Re: [nyphp-talk] Adding indexes

2010-03-23 Thread Hans Zaunere
> > One caveat to this is that mysql will only use one index per table in > > your query. > > I've never heard that before. Do you have a citation from the manual on > MySQL's website, please? It's thrown around through some of the links Rob mentioned, but it's true and notorious issue with inde

Re: [nyphp-talk] Adding indexes

2010-03-23 Thread Rob Marscher
On Mar 23, 2010, at 10:16 AM, Daniel Convissor wrote: > On Mon, Mar 22, 2010 at 01:42:14PM -0400, Rob Marscher wrote: >> >> One caveat to this is that mysql will only use one index per table in >> your query. > > I've never heard that before. Do you have a citation from the manual on > MySQL's

Re: [nyphp-talk] Adding indexes

2010-03-23 Thread Daniel Convissor
On Mon, Mar 22, 2010 at 01:42:14PM -0400, Rob Marscher wrote: > > One caveat to this is that mysql will only use one index per table in > your query. I've never heard that before. Do you have a citation from the manual on MySQL's website, please? Thanks, --Dan -- T H E A N A L Y S I S

Re: [nyphp-talk] Adding indexes

2010-03-22 Thread Daniel Convissor
Hi Nick: > $sql = "select dt1.*, d.* from > driver d join > (select `driver`, date(`leave`), sum(`points`) as pnts, > sum(`xpnts`) as xpnts from check_head > where date(`leave`) = '".$sdate."' > group by `driver`) dt1 > on dt1.driver = d.id_num w

Re: [nyphp-talk] Adding indexes

2010-03-22 Thread Rob Marscher
On Mar 22, 2010, at 1:31 PM, John Campbell wrote: ...snip... > 1: add an index on the timestamp 'leave' ...snip... > This is because mysql never uses indexes when a function is on the > left hand side. > There is no "formula" to follow, but you need to intuitively > understand how relational datab

Re: [nyphp-talk] Adding indexes

2010-03-22 Thread John Campbell
On Mon, Mar 22, 2010 at 11:00 AM, Nicholas Hart wrote: > For example: >     $sql = "select dt1.*, d.* from >         driver d join >         (select `driver`, date(`leave`), sum(`points`) as pnts, >         sum(`xpnts`) as xpnts from check_head >         where date(`leave`) = '".$sdate."' >       

Re: [nyphp-talk] Adding indexes

2010-03-22 Thread Adrian Noland
In addition to what others said... There is a lot more instruction both online and offline, but here is a brief example illustrating EXPLAIN: http://www.experts-exchange.com/articles/Database/MySQL/3-Ways-to-Speed-Up-MySQL.html The docs can be a bit dense if you're not familiar with what you are

Re: [nyphp-talk] Adding indexes

2010-03-22 Thread Rob Marscher
On Mar 22, 2010, at 11:00 AM, Nicholas Hart wrote: > I am looking to analyze and speed up some of my queries by adding any > necessary indexes. Is there a formula to follow in adding indexes to > multiple join queries? I have made some attempts using explain but am not > sure I understand it a

Re: [nyphp-talk] Adding indexes

2010-03-22 Thread Anthony W
It depends on where the join is occurring. If you have a HABTM relationship between the join tables then a index should be added to the pivot table. If not then I would assume that the column you are joining on would be a candidate for an index. Do these tables have a PRIMARY KEY already est

[nyphp-talk] Adding indexes

2010-03-22 Thread Nicholas Hart
I am looking to analyze and speed up some of my queries by adding any necessary indexes. Is there a formula to follow in adding indexes to multiple join queries? I have made some attempts using explain but am not sure I understand it all that well. For example: $sql = "select dt1.*, d.* from