?
Solved

how does mysql handle NULLs in indexes

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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 Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

743 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