amitsolanki24_'s avatar

Create index for TinyInt datatype in mysql.

Hey,

I have a doubt should we create an index for tinyInt datatype in mysql DB.


column_name = is_active values either 0 or 1.

0 likes
7 replies
JussiMannisto's avatar

You can create one, sure. But it's going to have a limited effect due to its low cardinality.

It might be more effective as part of a composite index. It all depends on your queries.

1 like
Snapey's avatar

what are you hoping to achieve by undexing this column?

1 like
JussiMannisto's avatar

@amitsolanki24_ If you query against that column alone, add an index on it. If you use it in conjunction with other columns, consider adding a composite index.

If you really want to know, I suggest learning how indexes work. Then you'll be able to decide for yourself. If you're unsure if you got it right, you can generate test data and use explain and explain analyze to find issues.

If you're already querying against a good quality index, adding a composite index may not help much. With 1000 records it's meaningless. With 100 million records it might help. It depends on your data and the cardinality of the index.

Disclaimer: I haven't watched any of the videos I linked, but I know Francis creates quality tutorials.

1 like

Please or to participate in this conversation.