views:

16

answers:

0

Hi All,

MYSQL running on my machine is V-5.1.40 I am able to partition the Table as i wanted but when i am trying to query using the key which i used to partition the table it does not take effect it still considers all the partitions

below is the code i used and its o/p respectivly

ALTER TABLE testTable REMOVE PARTITIONING;

ALTER TABLE testTable
PARTITION BY RANGE (TO_DAYS(createdDate)) 
( 
    PARTITION p_2010_08_01 VALUES LESS THAN (TO_DAYS('2010-08-01 00:00:00')),
    PARTITION p_2010_08_07 VALUES LESS THAN (TO_DAYS('2010-08-07 00:00:00')),
    PARTITION p_2010_08_14 VALUES LESS THAN (TO_DAYS('2010-08-14 00:00:00')),
    PARTITION p_2010_08_21 VALUES LESS THAN (TO_DAYS('2010-08-21 00:00:00')),
    PARTITION p_2011_08_28 VALUES LESS THAN (TO_DAYS('2011-08-28 00:00:00')) 
);

Query OK, 109286 rows affected (0.69 sec) Records: 109286 Duplicates: 0 Warnings: 0

SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS, AVG_ROW_LENGTH, DATA_LENGTH FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME LIKE 'testTable';
+----------------------------+----------------+------------+----------------+-------------+
| TABLE_NAME                 | PARTITION_NAME | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH |
+----------------------------+----------------+------------+----------------+-------------+
| testTable | p_2010_08_01   |          0 |              0 |           0 |
| testTable | p_2010_08_07   |      28870 |            265 |     7677924 |
| testTable | p_2010_08_14   |      80415 |            229 |    18479040 |
| testTable | p_2010_08_21   |          1 |             76 |          76 |
| testTable | p_2011_08_28   |          0 |              0 |           0 |
+----------------------------+----------------+------------+----------------+-------------+

5 rows in set (0.01 sec)

ALTER TABLE testTable DROP PARTITION p_2010_08_01;

Query OK, 0 rows affected (0.71 sec) Records: 0 Duplicates: 0 Warnings: 0

SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS, AVG_ROW_LENGTH, DATA_LENGTH FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME LIKE 'testTable';
+----------------------------+----------------+------------+----------------+-------------+
| TABLE_NAME                 | PARTITION_NAME | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH |
+----------------------------+----------------+------------+----------------+-------------+
| testTable | p_2010_08_07   |      28870 |            265 |     7677924 |
| testTable | p_2010_08_14   |      80415 |            229 |    18479040 |
| testTable | p_2010_08_21   |          1 |             76 |          76 |
| testTable | p_2011_08_28   |          0 |              0 |           0 |
+----------------------------+----------------+------------+----------------+-------------+

4 rows in set (0.00 sec)

EXPLAIN PARTITIONS SELECT count(*) FROM testTable WHERE createdDate = '2010-08-09 00:00:00';
+----+-------------+----------------------------+--------------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table                      | partitions   | type | possible_keys | key  | key_len | ref  | rows   | Extra       |
+----+-------------+----------------------------+--------------+------+---------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | testTable | p_2010_08_14 | ALL  | NULL          | NULL | NULL    | NULL | 109286 | Using where |
+----+-------------+----------------------------+--------------+------+---------------+------+---------+------+--------+-------------+

1 row in set (0.00 sec)

EXPLAIN PARTITIONS SELECT fieldX FROM testTable WHERE createdDate BETWEEN '2010-08-02 00:00:00' AND '2010-08-09 00:00:00' LIMIT 1;
+----+-------------+----------------------------+-----------------------------------------------------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table                      | partitions                                          | type | possible_keys | key  | key_len | ref  | rows   | Extra       |
+----+-------------+----------------------------+-----------------------------------------------------+------+---------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | testTable | p_2010_08_07,p_2010_08_14,p_2010_08_21,p_2011_08_28 | ALL  | NULL          | NULL | NULL    | NULL | 109286 | Using where |
+----+-------------+----------------------------+-----------------------------------------------------+------+---------------+------+---------+------+--------+-------------

+ 1 row in set (0.00 sec)

EXPLAIN PARTITIONS SELECT count(*) FROM testTable WHERE createdDate BETWEEN '2010-08-01 00:00:00' AND '2010-08-06 00:00:00';
+----+-------------+----------------------------+-----------------------------------------------------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table                      | partitions                                          | type | possible_keys | key  | key_len | ref  | rows   | Extra       |
+----+-------------+----------------------------+-----------------------------------------------------+------+---------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | testTable | p_2010_08_07,p_2010_08_14,p_2010_08_21,p_2011_08_28 | ALL  | NULL          | NULL | NULL    | NULL | 109286 | Using where |
+----+-------------+----------------------------+-----------------------------------------------------+------+---------------+------+---------+------+--------+-------------+

1 row in set (0.00 sec)

In all above conditions it is going through all partitions except the first where it only looks in to partition "p_2010_08_14"

is there any Issue/Bug with MYSQL V-5.1.40