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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:20:20+00:00 2026-06-12T04:20:20+00:00

I need to search for some user input patterns in database. is it efficient

  • 0

I need to search for some user input patterns in database.
is it efficient to use Regex in Mysql SELECT statement’s where clause ( in a scale of 10000 rows on an indexed column)?
My search is for dates and can be in these three forms :

  • 2012 that should match 2012 , 2012/* & 2012/*/*
  • 2012/10 that should match 2012/10 & 2012/10/*
  • 2012/10/3 that should match only 2012/10/3

Note: I have three columns that should be checked for this type of match separately.

  • 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-12T04:20:21+00:00Added an answer on June 12, 2026 at 4:20 am

    Although I can’t find a definite reference in the MySQL documentation, due to the index structure, regex matches can not use index lookups.

    They may scan indexes using the regex instead of scanning the full table, but any regex search will be more or less equivalent to a full table scan.

    If your regex starts with a constant string, you may want to structure the query as;

    SELECT * FROM TableA WHERE field LIKE 'tr%' AND field RLIKE 'tr[uae].*'
    

    to get some index help from the LIKE that – if matched from the start of the string – can use the index to its advantage.

    EDIT: Since your selects are fairly simple and match from the start of the string, you can just use LIKE to make them work, which will utilize indexes well;

    SELECT * FROM TableA WHERE field1='2012' OR field1 LIKE '2012/%'
    SELECT * FROM TableA WHERE field1='2012/10' OR field1 LIKE '2012/10/%'
    SELECT * FROM TableA WHERE field1='2012/10/3'
    

    The reason to split the comparison into two is to avoid a search for 2012/1 that would match 2012/10 with just a LIKE that covers both cases (ie LIKE '2012/1%').

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

Sidebar

Related Questions

I need to search some data depending on whether user enters a postcode or
I need to make a search page for some project. Input fields are: <h:inputText
I need to implement a search where user can input * as a wild
I want to use input from a user as a regex pattern for a
Many of us need to deal with user input, search queries, and situations where
I need to search dates in mysql however, if the column type is date
I need to search a string in mysql with php. I get an error
I have a form field that uses some Javascript to format user input 'price'
Classic scenario: Take user input, get a search-result and display it in pages to
i need some decision help today :-) interface A) an input field where the

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.