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

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

coldplay.xixi
coldplay.xixiforward
2020-07-01 17:59:472337browse

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 '%涂山%'
    can be replaced with:
  • SELECT * FROM msg_list WHERE INSTR(title,'涂山') > 0

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

    MsgList::where([
         'title' => ['instr','涂山']])
     ->select();

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!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete