[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Wildcard usage in mysql

Posted on 2007-08-09
2
Medium Priority
?
265 Views
Last Modified: 2013-11-05
I'm finding some really strange results when I do searches on my mysql database (360k records).
For instance, if I search for JOHN%% limit 0,100 -> it returns quickly.
But if I search for JOHN%Y -> It takes forever.

Can someone tell me why some of my searches are dog slow, while others are quick?  I'm generating indexes for each column I am searching against, hoping that will help.

Running on: 4.1.22-log on Mac OSX Tiger Server
0
Comment
Question by:ecuguru
2 Comments
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 800 total points
ID: 19661038
Its because if you use JOHN%Y a whole table scan is performed, as no index can be used (string must start wirh JOHN and END with Y). If you search FOR JOHN% a index can be used, as you are only looking for a string starting with JOHN.
0
 
LVL 17

Accepted Solution

by:
Aleksandar Bradarić earned 1200 total points
ID: 19661189
You could try using the way below to keep using the indexes and execute the query you want :)
---
... yourColumn LIKE 'JOHN%'  AND yourColumn LIKE '%Y' ...
---
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question