Home > Database > Mysql Tutorial > body text

Understand MySQ (Oracle) fuzzy query and use instr() instead of like to improve efficiency

coldplay.xixi
Release: 2020-07-01 17:59:47
forward
2445 people have browsed it

Understand MySQ (Oracle) fuzzy query and use instr() instead of like to improve efficiency

Everyone knows that the efficiency of like is very low, and it will be very slow if the amount of data is large. Today I discovered a built-in function instr() that is more efficient than like High

  • SELECT * FROM msg_list WHERE title LIKE '%涂山%'
    Copy after login
    can be replaced with:
  • SELECT * FROM msg_list WHERE INSTR(title,'涂山') > 0
    Copy after login

The methods used in ThinkPHP/Laravel are:

  1. Use whereRaw() to execute native INSTR()
  2. Modify the construction query (not recommended, but it is convenient to use)
    项目根目录\thinkphp\library\think\db\Builder.php
    Copy after login

    MsgList::where([
         'title' => ['instr','涂山']])
     ->select();
    Copy after login
  3. Related learning recommendations: mysql video tutorial

    The above is the detailed content of Understand MySQ (Oracle) fuzzy query and use instr() instead of like to improve efficiency. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template