sql >> Database teknologi >  >> RDS >> Mysql

MySQL LIKE vs LOCATE

Tilføjet 20. april 2015:Læs også Hallies svar nedenfor

Først men marginalt. Mest fordi den ikke behøver at lave en ekstra > 0 sammenligning.

mysql> SELECT BENCHMARK(100000000,LOCATE('foo','foobar'));
+---------------------------------------------+
| BENCHMARK(100000000,LOCATE('foo','foobar')) |
+---------------------------------------------+
|                                           0 |
+---------------------------------------------+
1 row in set (3.24 sec)

mysql> SELECT BENCHMARK(100000000,LOCATE('foo','foobar') > 0);
+-------------------------------------------------+
| BENCHMARK(100000000,LOCATE('foo','foobar') > 0) |
+-------------------------------------------------+
|                                               0 |
+-------------------------------------------------+
1 row in set (4.63 sec)


mysql> SELECT BENCHMARK(100000000,'foobar' LIKE '%foo%');
+--------------------------------------------+
| BENCHMARK(100000000,'foobar' LIKE '%foo%') |
+--------------------------------------------+
|                                          0 |
+--------------------------------------------+
1 row in set (4.28 sec)


mysql> SELECT @@version;
+----------------------+
| @@version            |
+----------------------+
| 5.1.36-community-log |
+----------------------+
1 row in set (0.01 sec)


  1. Få første/sidste n poster pr. gruppe af

  2. At SHA512-hash en adgangskode i MySQL-database af Python

  3. SQL Server Stored Procedures fra Oracle®

  4. En tilgang til indeksjustering – del 1