2016-05-12 73 views
2

当使用匹配/对一个事务中,它似乎并没有从临时未提交的数据进行查询:匹配/反对和交易

start transaction; 

insert into feed_full_text (feed_id, full_text) values (5000008, "lorem ipsum"); 

select feed_id, full_text 
from feed_full_text 
where feed_id = 5000008 and match(full_text) against("lorem" in boolean mode) 
order by feed_id desc 
limit 1; 

commit 

不返回任何结果,但是:

start transaction; 

insert into feed_full_text (feed_id, full_text) values (5000008, "lorem ipsum"); 

select feed_id, full_text 
from feed_full_text 
where feed_id = 5000008 
order by feed_id desc 
limit 1; 

commit 

返回刚插入的行,以及:

insert into feed_full_text (feed_id, full_text) values (5000008, "lorem ipsum"); 

select feed_id, full_text 
from feed_full_text 
where feed_id = 5000008 and match(full_text) against("lorem" in boolean mode) 
order by feed_id desc 
limit 1; 

也返回该行。这是一个错误还是我错过了什么?我在使用5.7.11版本支持InnoDB中的全文索引。

+0

可能重复的[是否可以插入,然后选择一个接一个插入的行?](http://stackoverflow.com/questions/14201947/is-it-possible-to-insert-and-然后选择插入的行一个接一个) –

回答

2

这是预期的行为。该documentation说:

InnoDB的全文索引事务处理
InnoDB的FULLTEXT索引有特殊原因事务处理特点的高速缓存和批量处理的行为。具体而言,在事务提交时处理FULLTEXT索引上的更新和插入,这意味着FULLTEXT搜索只能看到已提交的数据。

+0

我相信他不会看到_any_数据,直到他承诺交易。 –

+1

你为什么这么想?只有全文索引被推迟到事务结束。同一事务中的普通SELECT应该可以看到插入的数据,但不同事务中的SELECT不会看到它。 – Barmar