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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:00:56+00:00 2026-05-13T06:00:56+00:00

Given a (simplified) table CREATE TABLE `transactions` ( `ID` bigint(20) NOT NULL AUTO_INCREMENT, `CREATION_DT`

  • 0

Given a (simplified) table

CREATE TABLE  `transactions` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `CREATION_DT` datetime DEFAULT NULL,
  `STATUS_IND` int(11) DEFAULT NULL,
  `COMPANY_ID` bigint(20) DEFAULT NULL,
  `AMOUNT` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `FKE7E81F1ED170D4C9` (`COMPANY_ID`),
  KEY `RPTIDX_CREATION_DT` (`CREATION_DT`),
) ENGINE=InnoDB AUTO_INCREMENT=5241784 DEFAULT CHARSET=latin1;

and a common, relatively expensive query

UPDATE transactions
SET STATUS_IND = 5
WHERE
COMPANY_ID = ?
 and (STATUS_IND = 3 or STATUS_IND = 7)
 and CREATION_DT >= ? and CREATION_DT <= ?

I’m trying to determine if there is a better index strategy. Reads will most commonly

SELECT * FROM transactions WHERE COMPANY_ID=? ORDER BY CREATION_DT

COMPANY_ID is fairly selective (we have hundreds of companies in the table, growing quickly). STATUS_IND is not very selective (there are 5 common statuses and a few less common ones), and it’s value frequently changes (COMPANY_ID and CREATION_DT never change for a given row). CREATION_DT is fairly selective and getting more selective over time as we add more transactions to the system.

My initial thought is to replace the two existing keys with a compound key containing either COMPANY_ID+CREATION_DT or COMPANY_ID+STATUS_IND+CREATION_DT. Alternatively, possibly COMPANY_ID+CREATION_DT+STATUS_IND and change the order in the Update’s WHERE clause?

Also, is there a good reference that explains how InnoDB uses secondary compound indexes?

  • 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-13T06:00:57+00:00Added an answer on May 13, 2026 at 6:00 am

    My initial thought is to replace the two existing keys with a compound key…

    This a better approach than individual keys.
    Compound/covering index/key executes from left to right, meaning that the order of the list is important as it is read left to right. For example, if you define the index as: COMPANY_ID, CREATION_DT, STATUS_IND, the following combinations can trigger the use of the index:

    1. COMPANY_ID
    2. COMPANY_ID, CREATION_DT
    3. COMPANY_ID, CREATION_DT, STATUS_IND

    So if you only had CREATION_DT, or CREATION_DT, STATUS_IND – the index would not be used.

    The order doesn’t matter in the WHERE clause – just as long as the columns are referenced.

    Keep in mind too that all indexes for a MyISAM table can only sum up to 1000 bytes long (767 bytes for InnoDB tables), as designed.


    BTW: I rewrote your UPDATE statement:

    UPDATE transactions
       SET STATUS_IND = 5
     WHERE COMPANY_ID = ?
       AND STATUS_IND IN (3, 7)
       AND CREATION_DT BETWEEN ? AND ?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 356k
  • Answers 356k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT * FROM table1 t1 left outer join table2 t2… May 14, 2026 at 8:52 am
  • Editorial Team
    Editorial Team added an answer Assuming you're talking about the o'Reilly MultipartRequest it'll always be… May 14, 2026 at 8:52 am
  • Editorial Team
    Editorial Team added an answer You can use this snippet to rebuild the AppCache. Do… May 14, 2026 at 8:52 am

Related Questions

I have a job that performs several validation checks on rows in several tables
I have a somewhat complicated assortment of tables for which I need to do
I have a database where I store objects. I have the following (simplified) schema
I am using the SQLite database and have the following persistent class (simplified): public
I have a bit of code that basically displays the last x (variable, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.