Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6762877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:24:39+00:00 2026-05-26T14:24:39+00:00

I have a table ‘fvs_data’ with a timestamp column that I have used for

  • 0

I have a table ‘fvs_data’ with a timestamp column that I have used for a partition. The query optimizer doesn’t seem to be selecting the correct partitions if I have a complex query. For example, this query

EXPLAIN PARTITIONS SELECT * FROM `fvs_data` WHERE `timestamp` = '2011-11-02'

uses the correct partition, as show in the partitions list: p_2011_44, since TO_DAYS(‘2011-11-02’)=734808.

But if add another condition that should return the exact same partition, then it wants to check one of the other partitions

EXPLAIN PARTITIONS SELECT * FROM `fvs_data` WHERE `timestamp` > '2011-11-01' AND `timestamp` < '2011-11-03'

Which returns p_2011_42,p_2011_44 for the partition list. Here is my CREATE TABLE syntax

CREATE TABLE `fvs_data` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `fvs_client_id` int(11) NOT NULL,
 `timestamp` datetime NOT NULL,
 `setupid` char(20) NOT NULL,
 `assyline` char(20) NOT NULL,
 `machine` char(20) NOT NULL,
 `side` char(20) NOT NULL,
 `module` char(20) NOT NULL,
 `fixtureid` char(20) NOT NULL,
 `fixturepos` char(20) NOT NULL,
 `feedpos` char(20) NOT NULL,
 `partnum` char(20) NOT NULL,
 `vendor` char(20) NOT NULL,
 `tid` char(20) NOT NULL,
 `quant` char(20) NOT NULL,
 `status` char(32) NOT NULL,
 `oper` char(20) NOT NULL,
 `lane1` char(20) NOT NULL,
 `lane2` char(20) NOT NULL,
 `sn` char(20) NOT NULL,
 `totalcomp` char(20) NOT NULL,
 PRIMARY KEY (`id`,`timestamp`),
 KEY `fvs_client_id` (`fvs_client_id`),
 KEY `setupid` (`setupid`),
 KEY `assyline` (`assyline`),
 KEY `machine` (`machine`),
 KEY `side` (`side`),
 KEY `module` (`module`),
 KEY `fixtureid` (`fixtureid`),
 KEY `fixturepos` (`fixturepos`),
 KEY `feedpos` (`feedpos`),
 KEY `partnum` (`partnum`),
 KEY `vendor` (`vendor`),
 KEY `tid` (`tid`),
 KEY `status` (`status`),
 KEY `oper` (`oper`),
 KEY `lane1` (`lane1`),
 KEY `lane2` (`lane2`),
 KEY `sn` (`sn`)
) ENGINE=MyISAM AUTO_INCREMENT=36032 DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE ( TO_DAYS(timestamp))
(PARTITION p_2011_42 VALUES LESS THAN (734796) ENGINE = MyISAM,
PARTITION p_2011_43 VALUES LESS THAN (734803) ENGINE = MyISAM,
PARTITION p_2011_44 VALUES LESS THAN (734810) ENGINE = MyISAM,
PARTITION p_2011_45 VALUES LESS THAN (734817) ENGINE = MyISAM) */

I’m trying to do weekly partitions, but not based on real weeks starting with Sunday, I just divided the day of the year by 7 and used that to create a partition name.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:24:39+00:00Added an answer on May 26, 2026 at 2:24 pm

    The partition pruning will always check the first partition, regardless of the values you are searching for. This has to do with the way partitioning stores NULLs in the first partition.

    To workaround this and optimize range partitioning, create an initial partition for values less than any you would normally store:

    ...
    PARTITION BY RANGE ( TO_DAYS(timestamp))
    (
    PARTITION p_0000 VALUES LESS THAN (0) ENGINE = MyISAM, -- NULLs end up here
    PARTITION p_2011_42 VALUES LESS THAN (734796) ENGINE = MyISAM,
    PARTITION p_2011_43 VALUES LESS THAN (734803) ENGINE = MyISAM,
    PARTITION p_2011_44 VALUES LESS THAN (734810) ENGINE = MyISAM,
    PARTITION p_2011_45 VALUES LESS THAN (734817) ENGINE = MyISAM
    PARTITION p_MAX VALUES LESS THAN MAXVALUE ENGINE = MyISAM
    )
    

    Of course your timestamp column is NOT NULL so that first partition will be empty, and therefore very quick to search.

    P.S.: You should also add a partition to catch any large values outside the range of any other partition. Otherwise inserting such rows will fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table that has date field. When I run a query, I see
I have table with some fields that the value will be 1 0. This
I have table A in Oracle that has a primary key (id). I need
i have table in my database that have senestive data such as password field
I have table defined with FlexiGrid. Call to all variables is ok. One column
I have table 'pages' in my database. I have noticed that cakePHp has a
I have table with Timestamp, temperature and humidity. I want to have the average
I have table named A with column B defined int not null Primary Key
I have table named lantable in sqlite database where there is a column named
I have table that uses inline editing with ajax to modify the fields. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.