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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:12:05+00:00 2026-05-12T08:12:05+00:00

I am curious as to whether CREATE INDEX idx ON tbl (columns); vs. CREATE

  • 0

I am curious as to whether

CREATE INDEX idx ON tbl (columns);

vs.

CREATE UNIQUE INDEX idx ON tbl (columns);

has a significant algorithmic performance benefit in PostgreSQL or MySQL implementations when scanning the indexed column(s), or whether the UNIQUE keyword simply introduces a unique constraint alongside the index.

I imagine it is probably fair to say that there is a marginal benefit insofar as indexes are likely to be internally implemented as some sort of hash1-like structure, and collision handling by definition result in something other than O(1) performance. Given this premise, it is likely that if a large percentage of values are identical than the structure degenerates into something linear.

So, for purposes of my question, assume that the distribution of values is relatively discrete and uniform.

Thanks in advance!

1 Which is a matter of pure speculation for me, as I am not familiar with RDBM internals.

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

    If your data are unique, you should create a UNIQUE index on them.

    This implies no additional overhead and affects optimizer’s decisions in certain cases so that it can choose a better algorithm.

    In SQL Server and in PostgreSQL, for instance, if you sort on a UNIQUE key, the optimizer ignores the ORDER BY clauses used after that (since they are irrelevant), i. e. this query:

    SELECT  *
    FROM    mytable
    ORDER BY
            col_unique, other_col
    LIMIT 10
    

    will use an index on col_unique and won’t sort on other_col because it’s useless.

    This query:

    SELECT  *
    FROM    mytable
    WHERE   mycol IN
            (
            SELECT  othercol
            FROM    othertable
            )
    

    will also be converted into an INNER JOIN (as opposed to a SEMI JOIN) if there is a UNIQUE index on othertable.othercol.

    An index always contains some kind of a pointer to the row (ctid in PostgreSQL, row pointer in MyISAM, primary key/uniquifier in InnoDB) and the leaves are ordered on these pointers, so in fact every index leaf is unique is some way (though it may not be obvious).

    See this article in my blog for performance details:

    • Making an index UNIQUE
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was curious whether anyone has any suggestions for performance testing libraries and frontends
Pascal is my study language and I am curious whether C# also has the
I'm curious whether many of us who do design or take design decisions have
I'm curious to know whether the PDFKit framework is available for use within the
Although I'm doubtful, I'm curious as to whether it's possible to extract primitive-type template
curious if anyone might have some insight in how I would do the following
Curious to know how people set up their personal and/or work development environment, in
Curious to get people's thoughts. I conduct frequent interviews, and have had enough in
Curious as to 99.95% uptime REALLY means; Is it really going to go down
I curious to how different people solve integration of systems. I have a feeling

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.