2017-08-30 107 views
0

我在MariaDB中發現了一些內容,我不知道如何調查或修復。它只發生在Windows上。 Linux上的MariaDB和Windows上的MySQL都運行良好。可能/可能我正在做一些明顯錯誤的事情,但我很感興趣。子查詢在Windows中不工作,但在Linux上工作

我試圖重現在一個簡單的表中提供更多的信息,但它實際上工作,所以我不能再現。當然別的東西正在影響這種行爲,但我不知道是什麼。

問題:使用IN的子查詢不起作用。這裏是整個查詢:

Select table1.entityKey 
from table1 
where table1.Deleted = 0 
and table1.MasterKey is null 
and table1.entityTypeKey = 8 
and table1.entityKey in 
    (select table2.entityKey 
    from table2 
    where table2.Flag <> 2 
    and (table2.IndexKey = 4 and MATCH (table2.xhtmltext) AGAINST ('gold'))) 
order by table1.entityKey DESC 

對於我的數據集,這應該返回值2和3,但給出了一個空集。

所以我分裂的疑問,我覺得這一點: 子查詢正確返回2,3和4,

select table2.entityKey 
    from table2 
    where table2.Flag <> 2 
    and (table2.IndexKey = 4 and MATCH (table2.xhtmltext) AGAINST ('gold')) 

如果我這些值傳遞給外部查詢,它正確地篩選出4,和給我正確的結果(2,3):

Select table1.entityKey 
from table1 
where table1.Deleted = 0 
and table1.MasterKey is null 
and table1.entityTypeKey = 8 
and table1.entityKey in 
    (2,3,4) 
order by table1.entityKey DESC 

這裏有什麼可能是錯誤的?

感謝

+0

如果一個子查詢和外部查詢返回單獨正確的結果,但他們的組合不,這是一個錯誤的指示。請通過https://jira.mariadb.org報告。對於Windows/Linux的差異,很可能你在Linux和Windows上有不同的MariaDB版本,其中一個有一個錯誤,而另一個沒有。比較每個服務器上的SELECT @@ version'的輸出。另一個可能的原因是服務器設置不同,並且配置之一再次顯示錯誤。如果版本相同,則比較「SHOW VARIABLES」的輸出(忽略路徑等)。 – elenst

+0

MyISAM? InnoDB的?兩個系統都一樣嗎? –

+0

這似乎確實是版本10.2及以上的錯誤。將做更多的測試並報告問題。 – costateixeira

回答

0

它通常是最好避免IN (SELECT ...)地方實際。你的情況是很容易轉變:

Select table1.entityKey 
    from table1 
    JOIN table2 USING(entityKey) 
    where table1.Deleted = 0 
     and table1.MasterKey is null 
     and table1.entityTypeKey = 8 
     and table2.Flag <> 2 
     and table2.IndexKey = 4 
     and MATCH (table2.xhtmltext) AGAINST ('gold')) 
    order by table1.entityKey DESC 

如果還是不行,請從兩臺機器提供EXPLAIN SELECT ...。也SHOW CREATE TABLE

相關問題