2016-05-12 71 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