Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to make a partitioned table with the following RANGE function

CREATE TABLE `fact_events` (
`event_key` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`event_type_key` tinyint(3) unsigned NOT NULL,
`analytic_file_id` bigint(20) unsigned NOT NULL ',
`sdk_session_id` bigint(20) unsigned NOT NULL,
`virtual_button_create_id` bigint(20) unsigned NOT NULL C,
 PRIMARY KEY (`event_key`),
 KEY `idx_events_event_type` (`event_type_key`),
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 
  PARTITION BY RANGE(FLOOR(event_key/100000))
 PARTITION p0 VALUES LESS THAN (0),
 PARTITION p1 VALUES LESS THAN (1),
 PARTITION p2 VALUES LESS THAN (2),
 PARTITION p3 VALUES LESS THAN (3),
 PARTITION p4 VALUES LESS THAN (4),
 PARTITION p513 VALUES LESS THAN MAXVALUE
 )

I keep getting

ERROR 1564 (HY000): This partition function is not allowed

Any ideas would be welcome thanks

share|improve this question
add comment

1 Answer

MySQL documents the partitioning functions here. The floor() function appears to have some special considerations. In this case, I think the issue might be that the division is returning a float/double result rather than a decimal result.

This is easily fixed in your case because you do not need to do the division:

CREATE TABLE `fact_events` (
    `event_key` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `event_type_key` tinyint(3) unsigned NOT NULL,
    `analytic_file_id` bigint(20) unsigned NOT NULL,
    `sdk_session_id` bigint(20) unsigned NOT NULL,
    `virtual_button_create_id` bigint(20) unsigned NOT NULL,
     PRIMARY KEY (`event_key`),
     KEY `idx_events_event_type` (`event_type_key`)
 ) PARTITION BY RANGE(event_key) (
     PARTITION p0 VALUES LESS THAN (0),
     PARTITION p1 VALUES LESS THAN (100000),
     PARTITION p2 VALUES LESS THAN (200000),
     PARTITION p3 VALUES LESS THAN (300000),
     PARTITION p4 VALUES LESS THAN (40000000),
     PARTITION p5 VALUES LESS THAN MAXVALUE
 )

EDIT:

As an explanation. floor() returns an integer value but not necessarily an integer type. Here is the documentation:

For exact-value numeric arguments, the return value has an exact-value numeric type. For string or floating-point arguments, the return value has a floating-point type.

When you divide two integers, you produce a floating point argument and this is not appropriate for partitioning.

share|improve this answer
 
thanks, I'll implement it that way, but how do you explain the issue with floor? doesn't floor return an integer by definition? –  adam Jun 30 '13 at 15:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.