Scenario: You want to create a secondary index for MYSQL (category_id, for example); but 80% of the time it's zero (we never search for it); and 20% it's meaningful (we will actual search for this).
How could you create the secondary index so that it doesn't index the zero value (which is useless)?
Example table:
create table Test(
id int primary key,
secondary_id int,
data text
)
The query is:
select * from Test where secondary_id=some_value