Stop Using LIKE '%...%' for Search Category: Database / MySQL

Stop Using LIKE '%...%' for Search Category: Database / MySQL

T

Theodoros Kafantaris

Published on December 07, 2025

Searching is a core feature of almost every app. The first instinct is often to use the LIKE operator with wildcards.

Code
                    -- The Performance Killer
SELECT * FROM articles WHERE content LIKE '%Laravel%';
                

The Problem: When you put a % at the start of the string (%Laravel), MySQL cannot use an index. It must scan every single character of every single row. As your table grows, your site crashes.

The Solution: Use MySQL's native Full-Text Search.

Code
                    -- 1. Add a Full Text Index
ALTER TABLE articles ADD FULLTEXT(content);

-- 2. Search instantly
SELECT * FROM articles WHERE MATCH(content) AGAINST('Laravel');
                

Why use it?

  1. Speed: It uses an inverted index (instant lookup).

  2. Relevance: It can sort results by how well they match (not just yes/no).

Share this post

Challenge Your Mind

NEW!

Take a break from reading and test your logic skills with our daily puzzle!

Latest Challenge: Dec 8, 2025

Daily Logic Ladder - Karl Marx

Play Today's Puzzle

About Our Blog

Explore where technology meets intellect. From technical tutorials to intellectual exploration—stay curious and inspired.

â’¸ 2025. All rights reserved by atomic