Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9025245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:13:30+00:00 2026-06-16T06:13:30+00:00

As a simplified example, imagine that I’m selling widgets. I sell them nationwide (in

  • 0

As a simplified example, imagine that I’m selling widgets. I sell them nationwide (in both the U.S. and Canada) but there are some that can only be sold in certain areas (one or more U.S. states or Canadian provinces).

I’d like a good way to store this information, coupled with a fast way to query for the widgets that are available to a given user. “U.S., 50 states and D.C.” is the most common value, so I’d rather not insert 51 rows.

MySQL doesn’t support bitmap indexes, so that’s ruled out.

Here are some combinations:

  • U.S. 50 states and D.C.
  • U.S. 50 states, D.C., Canada, but not Quebec.
  • U.S. 48 contiguous states and D.C.
  • U.S., D.C., but not Colorado
  • U.S., D.C., and territories (Puerto Rico, etc).

My user will have given me one value for their state/province and country.

Can you suggest a schema that provides good storage and fast matching?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:13:31+00:00Added an answer on June 16, 2026 at 6:13 am

    This is a MySQL SET type, assuming that you can keep your dataset down to 64 items (or, use multiple sets based on other conditions).


    I thought I would expand on my answer, because I think some people just don’t understand the power of the set. Example table:

    CREATE TABLE `Test` (
      `setid` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `setname` varchar(64) NOT NULL,
      `setstate` set('AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY') NOT NULL,
      PRIMARY KEY (`setid`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
    
    insert into `Test` values('1','test','AZ,CA,NJ,NM,NY,VA,VT');
    

    Note that we use a single set field for states. More complex uses will likely require use of multiple sets, but the slightly more horizontal qword for each record may be cheaper than adding a large # of extra join operations on a lookup table that could easily reach a huge # of records on its on.

    Below are 3 (functionally) equivalent pulls. Note that the bitmask is very much the fastest way to pull this data:

    SELECT * FROM Test WHERE setstate & 1000;
    

    For test #1, We use 1000 as the bitmask, because this corresponds to item #4 in our list (AZ). This is, by far, the fastest method… and there are few ways to store this data which will give you faster result potential.

    SELECT * FROM Test WHERE setstate LIKE '%AZ%';
    

    This method can use indexes, but will be somewhat slow because of the fuzzy match.

    SELECT * FROM Test WHERE FIND_IN_SET('AZ',setstate);
    

    This method will be faster than the fuzzy match, but its nature will pretty much require the use of a temporary table in most real-world uses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a simplified example, consider a ListView that can contain both sub-categories and book
Imagine you live in very simplified example land - and imagine that you've got
This is a simplified example, to make sure that there are no asynchronous fading/animation
Using this as a simplified example, assume I have a table that has some
Note that all the code is a simplified example in order to only communicate
Imagine I've got a data object that makes sense in an OO model, but
This is a simplified example that should be enough for the question. @interface MyClass:
Consider the overly simplified example below; some of it written with pseudocode for brevity.
Below is a simplified example that demonstrates the problem I am having. One hundred
is there any way to concatenate sliced querysets? its simplified example (i realize this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.