Solved

how does mysql handle NULLs in indexes

Posted on 2014-01-10
2
398 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
2 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 250 total points
Comment Utility
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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
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 …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now