Моя среда:
windows 7 sp1 64bit
mariadb 10.3.8
Я создаю процедуру как:
CREATE OR REPLACE PROCEDURE `num_of_zone`(IN zone_reg varchar(1000))
BEGIN
DECLARE person_num INT;
SELECT COUNT(*) INTO person_num FROM person WHERE address REGEXP zone_reg;
SELECT person_num FROM DUAL;
END;
А теперь яназовите его, процессор перейдет на 100%, позже мой сервис mariadb будет остановлен.Но если я запускаю sql с определенным zone_reg, например:
SELECT COUNT(*) INTO person_num FROM person WHERE address REGEXP 'River [1-4]U.*';
, это будет хорошо.
В чем моя ошибка, пожалуйста?
Мои тестовые базы данных и данные:
CREATE TABLE flup_person (
person_id int(11) NOT NULL,
address varchar(255) NOT NULL DEFAULT '',
flup_year int(11) NOT NULL DEFAULT 0,
flup_quarter int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE OR REPLACE VIEW yq AS
SELECT YEAR(CURDATE()) AS flup_year, QUARTER(CURRENT_TIMESTAMP()) AS flup_quarter
UNION
SELECT YEAR(CURDATE() - INTERVAL 1 QUARTER) AS flup_year, QUARTER(CURDATE() - INTERVAL 1 QUARTER) AS flup_quarter
UNION
SELECT YEAR(CURDATE() - INTERVAL 2 QUARTER) AS flup_year, QUARTER(CURDATE() - INTERVAL 2 QUARTER) AS flup_quarter
UNION
SELECT YEAR(CURDATE() - INTERVAL 3 QUARTER) AS flup_year, QUARTER(CURDATE() - INTERVAL 3 QUARTER) AS flup_quarter;
CREATE OR REPLACE VIEW flup_view AS
SELECT p.person_id, p.address
FROM flup_person AS p LEFT JOIN yq
USING (flup_year, flup_quarter)
GROUP BY p.person_id;
CREATE OR REPLACE PROCEDURE num_of_zone(IN zone_reg varchar(1000))
BEGIN
DECLARE person_num int;
SELECT COUNT(*) INTO person_num FROM flup_view WHERE address REGEXP zone_reg;
SELECT person_num FROM DUAL;
END;
INSERT INTO flup_person(person_id, address, flup_year, flup_quarter)
VALUES
(2, 'River 1Uz', 2018, 1),
(3, 'River 2Uz', 2018, 3),
(4, 'River 15Ud', 2018, 2);
Последнее, я использую:
CALL num_of_zone('River [1-2].*');
Это остановит mariadb.
Но используйте:
SELECT COUNT(*) FROM flup_view WHERE address REGEXP 'River [1-2].*';
Это нормально.