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 8970397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:43:21+00:00 2026-06-15T17:43:21+00:00

Lets say i have this sample table: CREATE TABLE `users` ( `id` INT NOT

  • 0

Lets say i have this sample table:

CREATE  TABLE `users` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `name` VARCHAR(512) NULL ,
   `lastname` VARCHAR(512) NULL ,
   `country` VARCHAR(256) NULL ,
   `tags` VARCHAR(512) NULL ,
PRIMARY KEY (`id`) );

Basically the “tags” column is just key words that are set for the user

Now what i want to do is be able to search for a user based on the name and tags
To have fast search, i would had to create an index on “name” and “tags”

So to create index should i do:

ALTER TABLE `vidhucr1_serverlist`.`new_table` 
ADD INDEX `INDEX` (`name` ASC, `tags` ASC) ;

or

ALTER TABLE `vidhucr1_serverlist`.`new_table` 
ADD INDEX `INDEX1` (`name` ASC) 
, ADD INDEX `INDEX2` (`tags` ASC) ;
  • 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-15T17:43:22+00:00Added an answer on June 15, 2026 at 5:43 pm

    Having a single index (name, tags) should be better as long as your query filters names and tags. If your query should omit tags, the index would be useless (last statement under example 1). Also, I hope that you do not have multiple “tags” in the tags field.

    Example 1 – Composite Index

    Indexes: INDEX (name, tags)

    Index would be used for SELECT ... WHERE name = '...' AND tags = '...' or SELECT ... WHERE tags = '...' AND name = '...'

    | ID | SELECT_TYPE | TABLE | TYPE | POSSIBLE_KEYS |   KEY | KEY_LEN |         REF | ROWS |       EXTRA |
    --------------------------------------------------------------------------------------------------------
    |  1 |      SIMPLE | users |  ref |         INDEX | INDEX |    1536 | const,const |    1 | Using where |

    Index would be used for SELECT ... WHERE name = '...'

    | ID | SELECT_TYPE | TABLE | TYPE | POSSIBLE_KEYS |   KEY | KEY_LEN |   REF | ROWS |       EXTRA |
    --------------------------------------------------------------------------------------------------
    |  1 |      SIMPLE | users |  ref |         INDEX | INDEX |     768 | const |    1 | Using where |

    No index used for SELECT ... WHERE tags = '...'

    | ID | SELECT_TYPE | TABLE | TYPE | POSSIBLE_KEYS |    KEY | KEY_LEN |    REF | ROWS |       EXTRA |
    ----------------------------------------------------------------------------------------------------
    |  1 |      SIMPLE | users |  ALL |        (null) | (null) |  (null) | (null) |    1 | Using where |

    Example 2 – Two Single Indexes

    Indexes: INDEX1 (name), INDEX2 (tags)

    Both indexes used for SELECT ... WHERE name = '...' AND tags = '...'

    | ID | SELECT_TYPE | TABLE | TYPE | POSSIBLE_KEYS |    KEY | KEY_LEN |   REF | ROWS |       EXTRA |
    ---------------------------------------------------------------------------------------------------
    |  1 |      SIMPLE | users |  ref | INDEX1,INDEX2 | INDEX1 |     768 | const |    1 | Using where |

    INDEX1 used for SELECT ... WHERE tags = '...'

    | ID | SELECT_TYPE | TABLE | TYPE | POSSIBLE_KEYS |    KEY | KEY_LEN |   REF | ROWS |       EXTRA |
    ---------------------------------------------------------------------------------------------------
    |  1 |      SIMPLE | users |  ref |        INDEX1 | INDEX1 |     768 | const |    1 | Using where |

    INDEX2 used for SELECT ... WHERE name = '...'

    | ID | SELECT_TYPE | TABLE | TYPE | POSSIBLE_KEYS |    KEY | KEY_LEN |   REF | ROWS |       EXTRA |
    ---------------------------------------------------------------------------------------------------
    |  1 |      SIMPLE | users |  ref |        INDEX2 | INDEX2 |     768 | const |    1 | Using where |
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say have this immutable record type: public class Record { public Record(int x,
Lets say i have this usercontrol public class test : UserControl { public int
Lets say I have these two tables: CREATE TABLE nodes ( id INTEGER PRIMARY
I have this table in postgreSQL v9.1: CREATE TABLE ad_treenodemm ( ad_tree_id numeric(10,0) NOT
Lets say I have a class A that is fairly simple like this -
Lets say I have this code: <?php class hello { var $greeting = hello;
Lets say I have this class in foobar-shared.lib: class FooBar { std::string m_helloWorld; }
Lets say we have this code: bool KeepGoing = true; DataInThread = new Thread(new
Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I
Let's say I have a user defined table type: create or replace type SrcCodeTbl

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.