全文搜索后MySql查询锁定

时间:2016-10-19 18:35:49

标签: mysql locking full-text-search

  • MySQL引擎:InnoDB
  • MySql版本:5.6.31

1.运行第一个简单查询

SELECT o.id
FROM tbl_oper o
WHERE o.id_oper_tip = 8 AND o.id_oper_naim = 6;

结果:7行

2.在同一张桌子上运行全文搜索

SELECT
    o.id,
    MATCH(o.full_text_search) AGAINST('7930' IN BOOLEAN MODE) 'match'
FROM tbl_oper o
WHERE 0 < MATCH(o.full_text_search) AGAINST('7930' IN BOOLEAN MODE)

结果:6行(无论如何)

3.重复第一个查询,结果:0行,但全文搜索仍然返回6行

4.没有&#34; AND&#34;关键字正常工作:

SELECT o.id
FROM tbl_oper o
WHERE o.id_oper_tip = 8

7行

SELECT o.id
FROM tbl_oper o
WHERE o.id_oper_naim = 6

500+行

5.第一个查询仅在重启后才有效。为什么呢?

从IDE,shell,php-app

运行查询时的结果相同

为tbl_oper创建语句:

CREATE TABLE 'tbl_oper' (
    'id'                INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    'id_oper_naim'      INT(10) UNSIGNED          DEFAULT NULL,
    'id_oper_tip'       INT(10) UNSIGNED          DEFAULT NULL,
    'num'               VARCHAR(20)               DEFAULT NULL,
    'data_oper'         DATE                      DEFAULT NULL,
    'time_oper'         VARCHAR(20)               DEFAULT NULL,
    'id_sotrZ'          INT(10) UNSIGNED          DEFAULT NULL,
    'id_fiz_deb'        INT(10) UNSIGNED          DEFAULT NULL,
    'id_yur_deb'        INT(10) UNSIGNED          DEFAULT NULL,
    'id_podrazdel_deb'  INT(10) UNSIGNED          DEFAULT NULL,
    'id_fiz_kred'       INT(10) UNSIGNED          DEFAULT NULL,
    'id_yur_kred'       INT(10) UNSIGNED          DEFAULT NULL,
    'id_podrazdel_kred' INT(10) UNSIGNED          DEFAULT NULL,
    'id_nds_stavka'     INT(10) UNSIGNED          DEFAULT NULL,
    'summa'             DECIMAL(10, 2)            DEFAULT NULL,
    'summa_nds'         FLOAT                     DEFAULT NULL,
    'comment'           TEXT,
    'prov'              INT(10) UNSIGNED          DEFAULT NULL,
    'num_kred'          VARCHAR(20)               DEFAULT NULL,
    'prem'              INT(11)                   DEFAULT NULL,
    'id_dealer'         INT(10) UNSIGNED          DEFAULT NULL,
    'full_text_search'  TEXT,
    PRIMARY KEY ('id'),
    KEY 'id_podrazdel_kred' ('id_podrazdel_kred'),
    KEY 'id_oper_naim' ('id_oper_naim'),
    KEY 'id_oper_tip' ('id_oper_tip'),
    KEY 'id_yur_deb' ('id_yur_deb'),
    KEY 'id_podrazdel_deb' ('id_podrazdel_deb'),
    KEY 'id_yur_kred' ('id_yur_kred'),
    KEY 'id_fiz_deb' ('id_fiz_deb'),
    KEY 'id_nds_stavka' ('id_nds_stavka'),
    KEY 'ct_oper_sotrz_idx' ('id_sotrZ'),
    KEY 'ct_oper_fiz_kred_idx' ('id_fiz_kred'),
    FULLTEXT KEY 'full_text_search' ('full_text_search'),
    CONSTRAINT 'ct_oper_fiz_deb' FOREIGN KEY ('id_fiz_deb') REFERENCES 'tbl_person' ('id') ON UPDATE CASCADE,
    CONSTRAINT 'ct_oper_fiz_kred' FOREIGN KEY ('id_fiz_kred') REFERENCES 'tbl_person' ('id') ON UPDATE CASCADE,
    CONSTRAINT 'ct_oper_naim' FOREIGN KEY ('id_oper_naim') REFERENCES 'spr_oper_naim' ('id') ON UPDATE CASCADE,
    CONSTRAINT 'ct_oper_sotrz' FOREIGN KEY ('id_sotrZ') REFERENCES 'tbl_person' ('id') ON UPDATE CASCADE,
    CONSTRAINT 'ct_oper_type' FOREIGN KEY ('id_oper_tip') REFERENCES 'spr_oper_tip' ('id') ON UPDATE CASCADE,
    CONSTRAINT 'ct_podrazdel_deb' FOREIGN KEY ('id_podrazdel_deb') REFERENCES 'tbl_podrazdel' ('id') ON UPDATE CASCADE,
    CONSTRAINT 'ct_podrazdel_kred' FOREIGN KEY ('id_podrazdel_kred') REFERENCES 'tbl_podrazdel' ('id') ON UPDATE CASCADE,
    CONSTRAINT 'ct_yur_deb' FOREIGN KEY ('id_yur_deb') REFERENCES 'tbl_yur' ('id') ON UPDATE CASCADE,
    CONSTRAINT 'ct_yur_kred' FOREIGN KEY ('id_yur_kred') REFERENCES 'tbl_yur' ('id') ON UPDATE CASCADE
)
    ENGINE = InnoDB
    AUTO_INCREMENT = 38357
    DEFAULT CHARSET = utf8

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我将数据库缩减为1个表,9行,3个索引。这是重复bug的最小设置; 没有外键,只有索引。

CREATE TABLE `operations` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name_id` int(10) unsigned DEFAULT NULL,
  `type_id` int(10) unsigned DEFAULT NULL,
  `description` text,
  PRIMARY KEY (`id`),
  KEY `name_id_idx` (`name_id`),
  KEY `type_id_idx` (`type_id`),
  FULLTEXT KEY `ft_idx` (`description`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8


id | name_id | type_id | description
---+---------+---------+------------
1  | 2       | 3       | "hello world"
2  | 3       | 1       | "pascal"
3  | 3       | 1       | "geeen apple"
4  | 6       | 8       | "deep hell"
5  | 5       | 1       | NULL
6  | 3       | 1       | NULL
7  | 2       | 3       | NULL
8  | 3       | 4       | NULL
9  | 6       | 8       | NULL

首先查询工作如果:

  • 服务器重启
  • 重新索引任何索引
  • 仍然是name_id = 6type_id = 8

在版本5.6.31,5.6.34

上检查了此错误

升级到5.7.16已解决问题;