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

  • SEARCH
  • Home
  • 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 6628261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:06:36+00:00 2026-05-25T22:06:36+00:00

This is similar to another question I posted, but I was told to split

  • 0

This is similar to another question I posted, but I was told to split them.

I have a InnoDB MYSQL table that stores a multi select name ( or ‘code’ as the table calls it), a parent object’s id (parent_id) and the name of the option selected in the multi select (name_id):

CREATE TABLE IF NOT EXISTS `v2_CA_venue_option_map` (
  `map_id` int(11) NOT NULL auto_increment,
  `code` varchar(30) NOT NULL,
  `parent_id` int(11) NOT NULL,
  `name_id` int(11) NOT NULL,
  PRIMARY KEY  (`map_id`),
  UNIQUE KEY `3way_unique` (`code`,`parent_id`,`name_id`),
  KEY `name_id` (`name_id`),
  KEY `filter` (`code`,`name_id`),
  KEY `parent_id` (`parent_id`),
  KEY `code` (`code`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=875156 ;

and a simple table to store the names (i figured i would show this because its used in the query):

CREATE TABLE IF NOT EXISTS `v2_CA_venue_option_name` (
  `name_id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY  (`name_id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 COMMENT='Venue Option Names' AUTO_INCREMENT=60 ;

CREATE TABLE IF NOT EXISTS `v2_CA_venues` (
  `venue_id` int(11) NOT NULL auto_increment,
  `status` char(1) NOT NULL,
  `name` varchar(255) NOT NULL,
  `url_key` varchar(255) NOT NULL,
  `city` varchar(255) NOT NULL,
  PRIMARY KEY  (`venue_id`),
  KEY `city` (`city`,`status`),
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 ;

That I would like to optimize for the following query:

SELECT v.name, v.venue_id, v.url_key
FROM `v2_CA_venue_option_map` map
JOIN `v2_CA_venue_option_map` map2 ON (map2.parent_id = map.parent_id)
JOIN `v2_CA_venue_option_map` map3 ON (map3.parent_id = map.parent_id)
JOIN `v2_CA_venues` v ON (v.venue_id = map.parent_id)
WHERE v.city = 'Nevada City'
AND map3.code = 'a_venue_types'
AND map3.name_id = 19
AND map.code = 'a_event_types'
AND map.name_id = 20
AND map2.code = 'a_event_types'
AND map2.name_id = 3
AND v.status = 'a'
  1. Are the indexes placed on the table offering the best performance for these Joins and WHEREs?
  2. Are any of the indexes useless?

The EXPLAIN for the above query:
enter image description here

Thank you so much! I am looking for advice on the way to get the best performace out of these tables.

  • 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-05-25T22:06:36+00:00Added an answer on May 25, 2026 at 10:06 pm

    FOR your v2_CA_venues table, I see you have an index ON( City, Status ). Use this as the FIRST IN your query. Your maps table could have 1000’s of entries, but how many for a single “City + Status”… much less. So now that at the top of your query will help optimize the rest. Using the keyword “STRAIGHT_JOIN” tells optimizer to do it in the order you’ve stated.

    What you have of an index of 3way_unique index, I would change (or add another index) with the smallest element as first position in the index… I would actually change the order to ( parent_id, name_id, code ). You could have 100 codes, but 1000’s of parent_ids. But now, you are looking for a specific parent ID that could have multiple codes… So now, your index would be down to just ex: the ONE Parent_ID and it may have 8 codes and you are looking for 3. You’ve just reduced your comparison set for the join.

    SELECT STRAIGHT_JOIN
          v.name, 
          v.venue_id, 
          v.url_key
       FROM 
          v2_CA_venues v
    
             join v2_CA_venue_option_map map 
                ON v.venue_id = map.parent_id
                AND map.name_id = 20
                and map.code = 'a_event_types'
    
             join v2_CA_venue_option_map map2
                ON v.venue_id = map2.parent_id
                AND map2.name_id = 3
                and map2.code = 'a_event_types'
    
             join v2_CA_venue_option_map map3
                ON v.venue_id = map3.parent_id
                AND map3.name_id = 19
                and map3.code = 'a_venue_types'
    
       where 
              v.City = 'Nevada City'
          and v.status = 'a'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there is another question that exists similar to this one but I
This is similar to another question (http://stackoverflow.com/questions/935556/mysql-dump-by-query) but I hope different enough. I want
I have posted a question on here previously asking similar advise, but this project
I have checked this similar question, but the suggestions did not solve my problem:
I posted another question similar. This is my old code as some ppl say
I have had another question similar to this and have tried to see if
I already posted a similar question but i got told to try and solve
I posted another question on a very similar topic, but turned out to be
Before I post this question, I found somehow similar question posted here . But
After reading this question , I have another similar question. Is there a simple

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.