Общие > Базы данных
LIKE и REGEXP в MYSQL
(1/1)
Foshvad:
Вопросец.
Можно ли в общем оценить соотношение скоростей обработки MYSQL’ем запросов с REGEXP и с LIKE?
Например, что быстрее будет выполнятся:
SELECT somefield from sometable WHERE somefield REGEXP ‘*abc*’
и
SELECT somefield from sometable WHERE somefield LIKE ‘%abc%’
обработка порядка 2000-10000 строк.
somefield имеет тип VARCHAR(255), индекс создан
Кстати, кто-нить знает, REGEXP индекс использует?
Макс:
--- Цитировать ---Можно ли в общем оценить соотношение скоростей обработки MYSQL’ем запросов с REGEXP и с LIKE?
--- Конец цитаты ---
Цитата из мана:
--- Цитировать ---`BENCHMARK(count,expr)\'
The `BENCHMARK()\' function executes the expression `expr\'
repeatedly `count\' times. It may be used to time how fast *MySQL*
processes the expression. The result value is always `0\'. The
intended use is in the `mysql\' client, which reports query
execution times:
mysql> select BENCHMARK(1000000,encode("hello","goodbye"));
+----------------------------------------------+
| BENCHMARK(1000000,encode("hello","goodbye")) |
+----------------------------------------------+
| 0 |
+----------------------------------------------+
1 row in set (4.74 sec)
The time reported is elapsed time on the client end, not CPU time
on the server end. It may be advisable to execute `BENCHMARK()\'
several times, and interpret the result with regard to how heavily
loaded the server machine is.
--- Конец цитаты ---
--- Цитировать ---Кстати, кто-нить знает, REGEXP индекс использует?
--- Конец цитаты ---
эта информация вроде в EXPLAIN SELECT должна покзываться
AlieN:
--- Цитировать ---
mysql> select benchmark(100000000,\'select * from anek where anek regexp"%abc%"\'
;
+--------------------------------------------------------------------+
| benchmark(100000000,\'select * from anek where anek regexp"%abc%"\') |
+--------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------+
1 row in set (2.42 sec)
mysql> select benchmark(100000000,\'select * from anek where anek like"%abc%"\');
+------------------------------------------------------------------+
| benchmark(100000000,\'select * from anek where anek like"%abc%"\') |
+------------------------------------------------------------------+
| 0 |
+------------------------------------------------------------------+
1 row in set (2.42 sec)
--- Конец цитаты ---
AlieN:
ЗЫ: а если поле еще и индексированное то ваще все летает
(у меня селерон но 1000000 запросов проскакивает за 0.01 с)
!хз почему %)
Навигация
Перейти к полной версии