我的问题是regexp似乎没有给出相同的结果,因为在不同的上下文中,相同的模式。例如,
str REGEXP 'a|b|c|d|e'
//not equal to
str REGEXP 'a' OR str REGEXP 'b' OR ...我对一个大型数据集执行以下查询,其中“content”是以源代码文件形式出现的文本。我做内部REGEXP搜索任何包含我的关键字列表的源文件。一旦我有了完整的列表,我会再次检查它,并检查哪个特定的关键字绊倒了它。这是存在差异的地方;当针对所有关键字检查一些文件trip时,但是当针对每个单独的关键字检查trip时则不会发生任何变化。
select
source_histories.id,
MAX(source_histories.master_event_id) as master_event_id,
source_histories.source_file_id,
source_histories.content REGEXP '[;{}[:space:]]break;' as break,
source_histories.content REGEXP '[;{}[:space:]]break ' as break_label,
source_histories.content REGEXP '[;{}[:space:]]continue;' as `continue`,
source_histories.content REGEXP '[;{}[:space:]]throw ' as throw,
source_histories.content REGEXP '[;{}[:space:]]return;' as return_void
from
source_histories,
(SELECT
DISTINCT source_file_id
from
source_histories
where
ifnull(content, '') REGEXP '[;{}[:space:]]break;|[;{}[:space:]]break |[;{}[:space:]]continue;|[;{}[:space:]]throw |[;{}[:space:]]return;'
LIMIT 100
) as sourceIdList
where
source_histories.source_file_id = sourceIdList.source_file_id
group by
source_histories.source_file_id;下面是包含此问题的结果部分。正如您所看到的,source_file_id 92和95在单独检查时没有匹配任何关键字,但在检查所有关键字时必须匹配。我已经查看了它们的源代码,它们确实包含一个或多个关键字。
id master_event_id source_file_id break break_label continue throw return_void
256 3260 63 1 0 0 1 0
258 3640 65 1 0 0 0 0
259 3640 66 0 0 0 1 0
320 93722 85 1 0 0 0 0
346 471 92 0 0 0 0 0
360 93731 95 0 0 0 0 0
483 96052 108 1 0 0 0 0
536 1010 112 0 0 0 1 0有人对我的问题有什么建议吗?这是由于视力过低,还是mySQL的细微差别造成的?
解决方案:问题与我分析数据的顺序有关。我发现唯一的源文件_ file _id符合我的标准,但不能保证相应的最新版本的文件(max master_event_id)具有关键字(S)。下面(无论多慢)是我找到的解决方案。
select
source_histories.id,
source_histories.master_event_id as master_event_id,
source_histories.source_file_id,
source_histories.content REGEXP '[;{}[:space:]]break;' as break,
source_histories.content REGEXP '[;{}[:space:]]break ' as break_label,
source_histories.content REGEXP '[;{}[:space:]]continue;' as `continue`,
source_histories.content REGEXP '[;{}[:space:]]throw ' as throw,
source_histories.content REGEXP '[;{}[:space:]]return;' as return_void
from
source_histories
inner join
(select
source_histories.id,
MAX(source_histories.master_event_id) as master_event_id,
source_histories.source_file_id
from
source_histories
inner join
(SELECT
DISTINCT source_file_id
FROM
source_histories
LIMIT 100
) as distinctSHList
on
source_histories.source_file_id = distinctSHList.source_file_id
group by
source_file_id
) as lastestSourceList
on source_histories.id = lastestSourceList.id
where
ifnull(content, '') REGEXP '[;{}[:space:]]break;|[;{}[:space:]]break |[;{}[:space:]]continue;|[;{}[:space:]]throw |[;{}[:space:]]return;';发布于 2014-07-06 03:14:10
问题不在于REGEX子句,而在于您选择的方式。
子查询将考虑到给定source_file_id的所有source_file_id记录,而主查询(由于分组)将只考虑给定source_file_id的一个source_histories记录。
要验证,从查询中删除GROUP BY和MAX子句并在source_histories.id上联接;结果应该匹配。
select
source_histories.id,
source_histories.source_file_id,
source_histories.content REGEXP '[;{}[:space:]]break;' as break,
source_histories.content REGEXP '[;{}[:space:]]break ' as break_label,
source_histories.content REGEXP '[;{}[:space:]]continue;' as `continue`,
source_histories.content REGEXP '[;{}[:space:]]throw ' as throw,
source_histories.content REGEXP '[;{}[:space:]]return;' as return_void
from
source_histories,
(SELECT
id
from
source_histories
where
ifnull(content, '') REGEXP '[;{}[:space:]]break;|[;{}[:space:]]break |[;{}[:space:]]continue;|[;{}[:space:]]throw |[;{}[:space:]]return;'
LIMIT 100
) as sourceHistoriesIdList
where
source_histories.id = sourceHistoriesIdList.idhttps://stackoverflow.com/questions/24591566
复制相似问题