Re: Conoscete un "proxy" per avere MySQL in ram?
Gianluca Sordiglioni <[email protected]> Mon, 19 May 2014 06:02:18 -0700 (PDT)
| Newsgroups | gmane.os.freebsd.italian.esperti |
|---|---|
| Message-ID | <[email protected]> |
ANALYZE TABLE pmtext ANALYZE TABLE pm ricostruisci la distribuzione delle chiavi. Se vuoi esagerare, anche OPTIMIZE TABLE. ________________________________ Da: RedFoxy <[email protected]> A: Domande e risposte dagli esperti di FreeBSD <[email protected]> Inviato: Lunedì 19 Maggio 2014 11:03 Oggetto: Re: Conoscete un "proxy" per avere MySQL in ram? Il giorno 18/mag/2014, alle ore 16:55, Andrea Brancatelli <[email protected]> ha scritto: Ok. Ricorda che explain è tuo amico. >Explain select .... >Ti dice le possible keys e quella selezionata. >Se è none sta facendo fulltable scan che in generale è male. > > Si è vero, uno scan completo è il male specialmente quando hai milioni di record, infatti tra le query “lente” ho: SELECT pmtext.pmtextid FROM pmtext AS pmtext LEFT JOIN pm AS pm USING(pmtextid) WHERE pm.pmid IS NULL; che ci impiega più di 4 secondi, e spesso non da risultati anche l’explain conferma l’uso delle chiavi mysql> explain SELECT pmtext.pmtextid FROM pmtext AS pmtext LEFT JOIN pm AS pm USING(pmtextid) WHERE pm.pmid IS NULL; +----+-------------+--------+-------+---------------+----------+---------+------------------------------------+---------+-------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------+-------+---------------+----------+---------+------------------------------------+---------+-------------------------+ | 1 | SIMPLE | pmtext | index | NULL | PRIMARY | 4 | NULL | 1053123 | Using index | | 1 | SIMPLE | pm | ref | pmtextid | pmtextid | 4 | softairmania_forum.pmtext.pmtextid | 1 | Using where; Not exists | +----+-------------+--------+-------+---------------+----------+---------+------------------------------------+---------+————————————+ Le tabelle hanno questi indici mysql> show keys from pm; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | pm | 0 | PRIMARY | 1 | pmid | A | 1314686 | NULL | NULL | | BTREE | | | | pm | 1 | pmtextid | 1 | pmtextid | A | 1314686 | NULL | NULL | | BTREE | | | | pm | 1 | userid | 1 | userid | A | 39838 | NULL | NULL | | BTREE | | | | pm | 1 | userid | 2 | folderid | A | 52587 | NULL | NULL | | BTREE | | | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 4 rows in set (0,00 sec) mysql> show keys from pmtext; +--------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +--------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | pmtext | 0 | PRIMARY | 1 | pmtextid | A | 1053053 | NULL | NULL | | BTREE | | | | pmtext | 1 | fromuserid | 1 | fromuserid | A | 14831 | NULL | NULL | | BTREE | | | | pmtext | 1 | fromuserid | 2 | dateline | A | 1053053 | NULL | NULL | | BTREE | | | +--------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 3 rows in set (0,00 sec) — RedFoxy Darrest http://www.redfoxy.it _______________________________________________ Esperti mailing list [email protected] http://mailman.gufi.org/mailman/listinfo/esperti _______________________________________________ Esperti mailing list [email protected] http://mailman.gufi.org/mailman/listinfo/esperti