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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:56:36+00:00 2026-05-15T08:56:36+00:00

In a MySQL database I have a table with the following primary key PRIMARY

  • 0

In a MySQL database I have a table with the following primary key

PRIMARY KEY id (invoice, item)

In my application I will also frequently be selecting on item by itself and less frequently on only invoice. I’m assuming I would benefit from indexes on these columns.

MySQL does not complain when I define the following:

INDEX (invoice),
INDEX (item),
PRIMARY KEY id (invoice, item)

But I don’t see any evidence (using DESCRIBE — the only way I know how to look) that separate indexes have been established for these two columns.

Are the columns that make up a primary key automatically indexed individually? Is there a better way than DESCRIBE to explore the structure of my table?

  • 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-15T08:56:37+00:00Added an answer on May 15, 2026 at 8:56 am

    I’m not intimately familiar with the internals of indices on mySql, but on the two database vendor products that I am familiar with (MsSQL, Oracle) indices are Balanced-Tree (B-Tree) structures, whose nodes are organized as a sequenced tuple of the columns the index is defined on (In the Sequence Defined) See Note

    So, unless mySql does it very differently, (probably not), any composite index (on more than one column) can be useable by any query that needs to filter or sort by a subset of the columns in the index, as long as the list of columns is compatible, i.e., if the columns, when sequenced the same as the sequenced list of columns in the complete index, is an ordered subset of the complete set of index columns, which starts at the beginning of the actual index sequence, with no gaps except at the end…

    In other words, this means that if you have an index on (a,b,c,d) a query that filters on (a), (a,b), or (a,b,c) can also use the index, but a query that needs to filter on (b), or (c), (b,c) or (a, c) will not be able to use the index…

    So in your case, if you often need to filter or sort on column item alone, you need to add another index on that column by itself…

    NOTE: Normally, when using the term Balanced tree, it is implied that each node in the tree may have a maximum of two sub-nodes or branches. This is then called a Balanced Binary tree. Indices in SQL Server are just balanced non-binary B-Trees, where the nodes can have more than two sub-nodes or branches. The index optimizer calculates how many branches to allocate to each node based on optimizing performance. The fewer sub-nodes that exist on each node, the taller (height or depth) the tree will be. The optimum number of branches (that maximizes performance in locating a specific record), depends on the number of discreet values of the index attributes within the total data set domain.

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

Sidebar

Related Questions

I have a database table with a primary key called PremiseID. Its MySQL column
I have the following task: there are a simple table from mysql database: <html>
I have the following two tables in my mysql database. Table Name: groups id
I have three mysql table from same database Db1. Three tables have following columns.
I have the following database -- MYSQL DROP TABLE IF EXISTS Attributes; DROP TABLE
I have the following table of counters: CREATE TABLE cache ( key text PRIMARY
I have the following mysql table schema: SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; -- -- Database: `network` --
I have a MySQL innodb database at 1.9GB, showed by following command. SELECT table_schema
I have a following scenario in my SQL Server 2005 database. zipcodes table has
I have table which contains double values stored in mysql database ...I need to

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.