[Solved] simple mysql regexp
Looking to automatically optimize YOUR SQL query? Start for free.

EverSQL Database Performance Knowledge Base

simple mysql regexp

Database type:

As the following statement indicated, it matches a string start with one or more digits following by a space. Could you explain to me why this end up with 0 instead of 1?
However, it outputs 1 if I simply removes ^. As I know, ^ matches the beginning of a string, didn't I use it incorrectly?
Thanks in advance.

SELECT "345 boxberry ave " REGEXP '^\d*[[.space.]][[:<:]]b';

[edit] Basically, I want to match any street name start with 'b'.

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Avoid Regular Expression Filtering (query line: 2): When a regular expression filtering is applied on an indexed column, the database's optimizer won’t be able to use the index. Consider replacing this call with an alternative condition that won’t use a regular expression.
The optimized query:
        '345 boxberry ave ' REGEXP '^\d*[[.space.]][[:<:]]b'

Related Articles

* original question posted on StackOverflow here.