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 8556577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:23:04+00:00 2026-06-11T15:23:04+00:00

I have insert query of this form: on INSERT into abc values …. on

  • 0

I have insert query of this form:

on INSERT into abc values .... on DUPLICATE KEY UPDATE .... 

In my original table without partitions, the unique key was on (subject_id, object_id) but now I am partitioning by ts and I am forced to have the unique key as (subject_id, object_id, ts) because of mysql requirement of having the partition key in all the unique keys.

This means my insert query will fail coz an insert with same subject_id and object_id (from some previous insert) but a different timestamp will be treated as a unique new row and will get inserted instead of the desired update.

Is there any workaround?

CREATE TABLE `abc` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `subject_id` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
  `object_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`,`ts`),
  UNIQUE KEY `userint_sub_type_obj` (`subject_id`,`object_id`, `ts`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
/*!50100 PARTITION BY RANGE (unix_timestamp(ts))
(PARTITION p2012_08_27 VALUES LESS THAN (1346025600) ENGINE = InnoDB,
 PARTITION p2012_08_28 VALUES LESS THAN (1346112000) ENGINE = InnoDB,
 PARTITION p2012_08_29 VALUES LESS THAN (1346198400) ENGINE = InnoDB,
 PARTITION p2012_08_30 VALUES LESS THAN (1346284800) ENGINE = InnoDB,
 PARTITION p2012_08_31 VALUES LESS THAN (1346371200) ENGINE = InnoDB) */
  • 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-06-11T15:23:05+00:00Added an answer on June 11, 2026 at 3:23 pm

    To put it shortly, there is no way that I know of to add a partition without making the partition key a part of all your unique (and therefore also primary) keys.

    http://dev.mysql.com/doc/refman/5.5/en/partitioning-limitations-partitioning-keys-unique-keys.html

    I actually had this same problem last week trying to drop a partition on an enabled/disabled column. There’s two solutions that came to mind.

    1. You can move the timestamp into a meta_info table and partition that. Your look ups that have a time condition can then utilize the partition without messing with your (subject_id, object_id) key. The overhead is of course you’ll need to do a join. If your table is huge, this may not be viable.
    2. Do a check before you update. Instead of using the ON DUPLICATE KEY option, you split the action into a SELECT to see if the record exists, then either an INSERT or an UPDATE depending on the answer to that.

    Needless to say I’ve found this restriction of partitioning to be a huge pain in the rear, but it does appear to be a limitation in MySQL and after some Google Fu and asking around, it seems like there is simple way around it.

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

Sidebar

Related Questions

I have this form which can insert/update values into database table. <div id=settingsdiv style=width:350px;
I have the field: APP_DATE (smalldatetime) I'm doing this query: INSERT INTO table (TYPE,
I have this MySQL query: $SQLquery = INSERT INTO `experimental`.`comments` (`comment_id`, `comment_dt`) VALUES (NULL,
I have an insert query that gets generated like this INSERT INTO InvoiceDetail (LegacyId,InvoiceId,DetailTypeId,Fee,FeeTax,Investigatorid,SalespersonId,CreateDate,CreatedById,IsChargeBack,Expense,RepoAgentId,PayeeName,ExpensePaymentId,AdjustDetailId)
I have this query that inserts rows, using a subquery like so: INSERT INTO
I am running this sort of query: insert into mytable (id, col1, col2) values
now i have this form post script <? if(isset($_POST['baslik'])) { $sql = INSERT INTO
I have a query insert into carsdescription (description,idCar) value (@description,@idCar) where idCar=@idCar; select nameOfCar
I have a query: insert into #tmpRcIzm select distinct v.id_art, 'Y' from openxml(@hDoc, '/art_komp/nol')
I'm getting this error when trying to insert data from a form into a

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.