Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how does mysql handle NULLs in indexes

Posted on 2014-01-10
2
Medium Priority
?
409 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 1000 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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

636 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