MySQL Forums
Forum List  »  Optimizer & Parser

MySQL can't find index = really slow query...
Posted by: Alessio Pianigiani
Date: September 25, 2006 05:53AM

Hello everybody!

I have to optimize a 7 join query...


SELECT a.PRATICA_ID,p.situaz,p.tipo_prat,d.ragsoc,d.telefono,d.indirizzo,d.comune_id,c.descr,c.provincia_ID,pr.descrizione,pr.regione_ID,r.regione_ID,r.descrizione,p.importo_capitale,n.notecli FROM anagrafe_debitori AS d,affidamenti_procuratore AS a,pratiche AS p,comuni AS c,province AS pr,regioni AS r,noteprat AS n WHERE a.anagrafe_procuratore_ID=4 AND a.fine IS NULL AND p.pratica_ID=a.pratica_ID AND n.pratica_ID=p.pratica_ID AND n.pratica_ID=34054 AND p.anagrafe_debitore_ID=d.anagrafe_debitore_ID AND c.comune_ID=d.comune_ID AND pr.provincia_ID=c.provincia_ID AND r.regione_ID=pr.regione_ID


The real problem is that "noteprat" and "affidamenti procuratore" tables takes about 9/10 seconds each to reach the exact row, and that's beacuse MySQl don't recognize index.
It's so strange because I use multiple indexes in each of the two tables and indexes are unique, related, and significatives..


DROP TABLE IF EXISTS `gecoprova`.`affidamenti_procuratore`;
CREATE TABLE `gecoprova`.`affidamenti_procuratore` (
`affidamento_procuratore_ID` int(10) NOT NULL,
`pratica_ID` int(10) NOT NULL,
`anagrafe_procuratore_ID` int(10) NOT NULL,
`inizio` datetime default NULL,
`fine` datetime default NULL,
`negativo` smallint(5) default NULL,
PRIMARY KEY (`affidamento_procuratore_ID`,`anagrafe_procuratore_ID`,`pratica_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


DROP TABLE IF EXISTS `gecoprova`.`noteprat`;
CREATE TABLE `gecoprova`.`noteprat` (
`serial` int(10) NOT NULL,
`pratica_ID` int(10) NOT NULL,
`numprat` int(10) default NULL,
`codcli` int(10) default NULL,
`notecli` longtext,
`noteint` longtext,
`tipo` varchar(4) default NULL,
PRIMARY KEY (`serial`,`pratica_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

pls help me if you can,
bye and thanks everybody for your replies

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL can't find index = really slow query...
4025
September 25, 2006 05:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.