Solved

how does mysql handle NULLs in indexes

Posted on 2014-01-10
2
404 Views
Last Modified: 2014-01-10
Hello

I'm a little unsure about how mysql handles nulls in indexes.

Can I have an index on a column that contains Nulls?

If I have an index based on a text field which can contain Nulls will mysql add the nulls to the index? Will they be added at the top or bottom if they are added (not that that matters 0 I'm just curious).

thanks
0
Comment
Question by:andieje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 250 total points
ID: 39771114
Hi.

Yes, you can have an index on a column that contains NULLs.  According to the manual, MySQL can leverage an index on column with NULLs to optimize IS NULL condition in WHERE clause.  Therefore, the answer is yes to your questions.

MySQL orders NULLs first if I remember correctly.
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 39771156
from what I know, NULL values are NOT indexed.

however, indeed some optimizations are done for NULL values vs NOT NULL query:
http://dev.mysql.com/doc/refman/5.0/en/is-null-optimization.html
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question