Pregunta

ejecutar MySQL 5.1.30 en Solaris 10. Como tengo una tabla que me repartirá en 12 de acuerdo con cada mes.

La estructura de la tabla de la siguiente manera

mysql> desc my_events;
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| event_id  | bigint(20)   | NO   | PRI | NULL    | auto_increment | 
| timestamp | timestamp    | NO   | PRI | NULL    |                | 
| object    | varchar(10)  | YES  |     | NULL    |                | 
| info      | text         | YES  |     | NULL    |                | 
+-----------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> SELECT PARTITION_NAME, TABLE_ROWS, PARTITION_EXPRESSION, PARTITION_DESCRIPTION FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA = 'test11' AND PARTITION_METHOD = 'RANGE';
+----------------+------------+----------------------+-----------------------+
| PARTITION_NAME | TABLE_ROWS | PARTITION_EXPRESSION | PARTITION_DESCRIPTION |
+----------------+------------+----------------------+-----------------------+
| p001           |          0 | to_days(timestamp)   | 733773                | 
| p002           |          0 | to_days(timestamp)   | 733804                | 
| p003           |      20863 | to_days(timestamp)   | 733832                | 
| p004           |     269336 | to_days(timestamp)   | 733863                | 
| p005           |    3094672 | to_days(timestamp)   | 733893                | 
| p006           |    2639348 | to_days(timestamp)   | 733924                | 
| p007           |     314010 | to_days(timestamp)   | 733954                | 
| p008           |          0 | to_days(timestamp)   | 733985                | 
| p009           |          0 | to_days(timestamp)   | 734016                | 
| p010           |          0 | to_days(timestamp)   | 734046                | 
| p011           |          0 | to_days(timestamp)   | 734077                | 
| p012           |          0 | to_days(timestamp)   | 734107                | 
+----------------+------------+----------------------+-----------------------+
12 rows in set (0.05 sec)

Cuando quiero para consultar determinada gama de días.

mysql> DESCRIBE PARTITIONS SELECT * FROM my_events where timestamp > '2009-03-01' and timestamp < '2009-03-30';
+----+-------------+-------------------+-------------------------------------------------------------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table             | partitions                                                  | type | possible_keys | key  | key_len | ref  | rows    | Extra       |
+----+-------------+-------------------+-------------------------------------------------------------+------+---------------+------+---------+------+---------+-------------+
|  1 | SIMPLE      | my_events | p001,p002,p003,p004,p005,p006,p007,p008,p009,p010,p011,p012 | ALL  | NULL          | NULL | NULL    | NULL | 6338229 | Using where | 
+----+-------------+-------------------+-------------------------------------------------------------+------+---------------+------+---------+------+---------+-------------+
1 row in set (0.01 sec)

consultar todas las particiones cuando se utiliza el tipo marca de tiempo para la marca de tiempo. Sin embargo, cuando se cambia el tipo de fecha y hora para la marca de tiempo, se consulta sólo 1 partición (P004).

mysql> DESCRIBE PARTITIONS SELECT * FROM my_events where timestamp > '2009-03-01' and timestamp < '2009-03-30';
+----+-------------+-------------------+------------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table             | partitions | type | possible_keys | key  | key_len | ref  | rows    | Extra       |
+----+-------------+-------------------+------------+------+---------------+------+---------+------+---------+-------------+
|  1 | SIMPLE      | my_events | p004       | ALL  | NULL          | NULL | NULL    | NULL | 6338229 | Using where | 
+----+-------------+-------------------+------------+------+---------------+------+---------+------+---------+-------------+
1 row in set (0.00 sec)

¿Cómo puedo consultar única partición 1, pero con el uso de tipo marca de tiempo para la marca de tiempo?

¿Fue útil?

Solución

He estado investigando esto y la respuesta corta es que no se puede de acuerdo con la http://bugs.mysql.com/bug.php?id=24245

"poda no se espera que trabajar para tablas con particiones en una columna TIMESTAMP, y se debe utilizar una columna DATETIME o DATE para este lugar ".

Otros consejos

Este es un buen artículo http: // dev.mysql.com/tech-resources/articles/testing-partitions-large-db.html

personalmente me gustaría tener un índice agrupado innodb PK compuesto sobre una partición hasta que mis necesidades de almacenamiento de datos quedé tonto - realmente tonto

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top