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

  • SEARCH
  • Home
  • 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 8215519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:48:51+00:00 2026-06-07T11:48:51+00:00

I have a table like this CREATE TABLE values ( id int(10) auto_increment NOT

  • 0

I have a table like this

CREATE TABLE values (
    id int(10) auto_increment NOT NULL, 
    molecule_id int(5) NOT NULL,
    descriptor_id int(5) NOT NULL,
    T double DEFAULT NULL,
    value double NOT NULL,
    PRIMARY KEY (id),
    KEY index1 (molecule_id, T),
    KEY index2 (descriptor_id, T)
) ENGINE=InnoDB;    

Rows of the table are many combinations of 3000 descriptor_ids, 600 molecule_ids and 3500 Ts with random double values (about 2 billion rows).

I was under the impression that for a query like

SELECT T, value FROM values WHERE molecule_id = X AND descriptor_id = Y

mysql would use both keys and then intersect the results. But doing an Explain extended on this query tells me it only uses index2, having chosen between index1 and index2.

molecule_id = X hits about 1/600 of the table.
descriptor_id = Y hits either a very small part of the table of the table (like 0.001%) or about 1/700, depending on Y.

It seems like intersecting would be faster than just using index2 and scanning the rest of the over ~2.5 million rows. Even if the 3000 descriptor_ids were evenly distributed it would still leave 800,000 rows to scan on average.

What am I missing?

  • 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-07T11:48:53+00:00Added an answer on June 7, 2026 at 11:48 am

    spencer7593 has it right. An index_merge only occurs in range situations. If your AND were an OR it would trigger an index_merge. However, since it is an AND, why not make a multi_column index on both molecule_id and descriptor_id? That will get you better results, and faster. If descriptor_id is more exclusive (as you mentioned) do this:

    ALTER TABLE values ADD INDEX descriptor_molecule (descriptor_id, molecule_id, T, value)

    As long as your query has both columns in the where clause with an AND condition, it will use this index. In this case, I would actually drop your index2, since if the query only has the descriptor_id column in the where clause, it can still use the descriptor_molecule index as a prefix index. Plus, indexing all 4 columns will create a covering index for the query you mentioned and thus speed up your query by quite a bit.

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

Sidebar

Related Questions

We have a DB like this: CREATE TABLE `jobs` ( `id` int NOT NULL
I have a table like this: CREATE TABLE book_info ( book_id VARCHAR(32) not null,
I have a MySQL table: CREATE TABLE documents ( id INT NOT NULL AUTO_INCREMENT,
So I have a table like this: create table `test` ( `testId` int(11) not
I have an MySQL table: CREATE TABLE responses ( id INT NOT NULL AUTO_INCREMENT,
I have something like this: create table account ( id int identity(1,1) primary key,
I have a testdata like this: DROP TABLE SELECT_PASS; CREATE TABLE SELECT_PASS(ID INT(20),TESTCASE VARCHAR(20),RESULT
I have this Tags table CREATE TABLE IF NOT EXISTS `Tags` ( `id_tag` int(10)
I currently have database setup like so: CREATE TABLE `article` ( `id` int(11) NOT
This is my table definition: CREATE TABLE orders_total ( orders_total_id int unsigned NOT NULL

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.