D
D
Dmitry2021-01-24 20:35:26
MySQL
Dmitry, 2021-01-24 20:35:26

How can this sql query be optimized?

Please tell me how to optimize this query.

use test1;
SELECT `firstname`, 
 `lastname`,
 `age`,
 `town`, 
 `desired_profession`,
 `id`,
 `payment`,
 `pol`,
 `birthmonth`,
 `birthyear`,
 `region`
 
FROM profil WHERE (`desired_profession` REGEXP 'бухгалтер|сметчик|менеджер по кредитам|копирайтер|корректор|турагент|экскурсовод|аналитик|журналист|спортивный|аналитик|переводчик|оператор|логист|диспетчер|провизор|оператор|call-центра|почтальон|курьер|фасовщик|официант|повар|тренер|Модератор|урбанист|вожатый|лингвист|агроном|эколог') BETWEEN 4 AND 4 AND (`age` BETWEEN 20 AND 31) AND (`pol` BETWEEN 3 and 3);


There was also a problem with loading the database, some dumps were not loaded, it was advised to execute this command after that, the request takes a very long time and issues it every other time (sometimes it doesn’t find anything) ALTER TABLE profil DROP PRIMARY KEY;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-01-24
@vabka

1. Do not use a regular expression.
2. Remove unnecessary ones BETWEEN x AND xand replace them with = x
3. After removing the regex, run explain and apply further optimizations based on it.

ALTER TABLE profile DROP PRIMARY KEY

Put the primary key back in place.

A
Aristarkh Deryapa, 2017-06-26
@isisTance

from tkinter.messagebox import *

shnugi = {
r: True
f: lambda msg, text: tkinter.showinfo(title=msg, text=text)
}

if shnugi["r"]:
shnugi["f"]("Title", "Description")

I have not worked with lambda, but the code seems to be working.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question