Re: mysql eluding query debugging?

2007-11-10 Thread Brent Baisley
A function on any column does not negate the use of the index. That  
only happens if you use a function in a filter part (join, where, etc.).


You may want to run optimize table on the 2 tables involved. That  
will update the table stats that mysql uses to optimize the queries.  
MySQL may occasionally be taking a different optimization path when  
it runs the query, which may or may not be the best path. Those may  
be the times your query is slow.  You'll notice in your explain it's  
looking in the movement_items table first.
Dan Nelson was correct about MySQL having to do 2300+ lookups in the  
second table, although in this case the second table is the  
movements table. Which is the opposite of what you are expecting in  
your query. You are correct, 2300 records should be a breeze and your  
query should always be fast. You want the movements table to be  
queried first.


I don't know your table structure, but it seems item_id is part of  
the movement_items table. Which means you should put item_id=21311 in  
the join statement.
...LEFT OUTER JOIN movements ON movements.id =  
movement_items.movement_id AND movement_items.item_id=21311


From the manual:
The LEFT JOIN condition is used to decide how to retrieve rows from  
table B. (In other words, any condition in the WHERE clause is not  
used.)


The part in () is the important part. The WHERE clause should only  
have information to filter the result set, not anything to filter the  
JOIN. That information should be in the JOIN.


Try making that change. I believe I explained what is happening and  
why. Although I may be wrong, please post if it doesn't work.  
Regardless, you want to see the movements table listed first in your  
EXPLAIN.


Brent


On Nov 9, 2007, at 3:46 PM, Moritz von Schweinitz wrote:

Thank your for your answer (even though i only got it because you  
sent it directly to me - somehow, the mailinglist-emails are not  
getting through to me. weird).


1.) All that can have a UNIQUE index, have one, ut the ones i am  
using here are not unique (except for movements.id, which is a  
PRIMARY).
2.) as far as i can see, the use of the function on the column  
quant shouldnt influence performance in this case - mysql should  
(and sais that it does inthe EXPLAIN, as far as i can tell), that  
it is using all availble indexes to reduce the numbers of examined  
rows to a mere 2300 rows, and then sums them up - which shouldn't  
take longer than a second, in my experience.
3.) i think i cant combine them in an index, because type_id and  
type_id are in different tables.


but my main problem is still that the first run of the query is  
slow, and the following ones are fast enough - this way, i cant  
really debig the query. any tips on how to manage that mysql stops  
doing whatever it is doing to make the following queries optimized?


thanks,

M.

Martin Gainty wrote:

some unknowns
1)Are all the columns you are referencing indexed with UNIQUE  
indexes?
2)Using a function on any column negates the use of the  
referencing index so

in your case you are doing a SUM(quant)
.is there any capability of denormalising say ..storing the sum  
preferably

in the movement items table
3)assuming either
Both item_id and type_id columns can be referenced via UNIQUE indexes
OR using a concatened index on item_id and type_id
will go a long way to speed up the query

Viel Gluck/
Martin
- Original Message -
From: Moritz von Schweinitz [EMAIL PROTECTED]
To: mysql@lists.mysql.com
Sent: Friday, November 09, 2007 1:16 PM
Subject: mysql eluding query debugging?




Ok, i don't get it.

I have the following query:
SELECT
SUM(quant)
FROM
movement_items
LEFT OUTER JOIN movements ON movements.id =  
movement_items.movement_id

WHERE
item_id = 21311
AND
movements.type_id = 1

where 'movement_items' has about 1.3M rows, and 'movements' about  
0.5M



rows.


EXPLAIN gives me the following:


++-+++- 
+

-+-+---+--+-+


| id | select_type | table  | type   | possible_keys   |
key | key_len | ref   | rows | Extra


|
  ++-++ 
+-+

-+-+---+--+-+


|  1 | SIMPLE  | movement_items | ref| movement_id,item_id |
item_id | 5   | const | 2327 |  
Using where



|


|  1 | SIMPLE  | movements  | eq_ref | PRIMARY,type_id |
PRIMARY | 4   | pague9.movement_items.movement_id |1 |  
Using where



|
  ++-++ 
+-+

-+-+---+--+-+


2 rows in set (0.01 sec)

which seems ok to me (2327 rows to examine should be a breeze,  
right?)


Now, my problem: sometimes, this query takes up to 10 seconds 

Re: NFS

2007-11-10 Thread Peter M. Groen
On Wednesday 07 November 2007, Charles Jardine wrote:
 I am planning to set up a system in which mysql servers access
 their data via NFS. All the computers involved run Solaris 10.
 NFS version 4 will be used.

 I plan to ensure that no NFS share is ever mounted by more than
 one client computer, and that no client computer ever runs more
 than one mysql server. There will thus be no attempt to share
 data between mysql servers using NFS.

 I am not planning to use ndbd.

 I have searched the manuals and found nothing that tells me that
 this will not work. All the warnings are either about performance,
 or about data sharing.

 Are there other reasons why I should not do as I plan?

 --
 Charles Jardine - Computing Service, University of Cambridge
 [EMAIL PROTECTED]Tel: +44 1223 334506, Fax: +44 1223 334679

Try an iscsi setup (pretty easy) with gfs (Global File System) on it. This 
will bring more joy and jubilation..
-- 
Peter M. Groen
Open Systems Development
Klipperwerf 12
2317 DZ  Leiden
Tel     : +31-(0)71-5216317
Mobile  : +31-(0)6-29563390
Email   : [EMAIL PROTECTED]
Skype   : peter_m_groen

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: mysql eluding query debugging?

2007-11-10 Thread Jeremy Cole

Hi Moritz,


Thus, my questions:
- what's wrong with that query? I know they are big tables, but 
according to EXPLAIN, this should be fast enough, because mysql's seeing 
the indexes just fine.


As others have said, likely nothing wrong with the query per se.  It 
just sounds like you're hitting disk instead of cache.


- how can i tell mysql to switch off whatever cache or performance thing 
it is that makes debugging such a PITA? is there a way to disable it 
just for this query? (SELECT SQL_NO_CACHE doesn't seem to make a difference)


There are a few caches at play here:

1. query cache - caches entire query results; not what you're hitting here

2. storage engine caches - key_buffer_size for MyISAM and 
innodb_buffer_pool_size for InnoDB; caches index data for MyISAM and 
index and row data (technically pages) for InnoDB


3. OS disk cache; caches any data accessed from disk, not tunable for 
MyISAM, tunable using innodb_flush_method=O_DIRECT for InnoDB


I would think what is happening is that you don't have a large enough 
cache at level 2 above, which means your data doesn't fit in cache 
inside MySQL, so it gets cached in the OS at level 3, which is rather 
fickle and will page things out when you may not expect it.


Alternately, your system is busy enough that things still get paged out 
at level 2 above in which case the solution isn't necessarily as simple.


Regards,

Jeremy

--
high performance mysql consulting
www.provenscaling.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]