我使用sereval表来存储文件:
files
包含有关每个文件的信息(id,date,extension ....)
files2000
包含2000年(id_file,content)
files2001
包含2001年的所有文件内容(id_file,content)
files2002
包含2002年的所有文件内容(id_file,content)
等......
问题是:如何在日期,扩展名和内容上搜索文件? 提前谢谢!
编辑:分隔表,因为只有一个表太重(超过200 000个文件;)
可以像这样构建表:
CREATE TABLE IF NOT NOT EXISTS files
(
id
mediumint(9)NOT NULL,
name
文本NOT NULL,
date
日期非空,
extension
文本NOT NULL,
KEY id
(id
)
)ENGINE = MyISAM DEFAULT CHARSET = latin1;
INSERT INTO files
(id
,name
,date
,extension
)价值观
(0,' File_1',' 2000-05-07',' PDF'),
(1,' File_2',' 2000-11-01',' ODT'),
(2,' File_3',' 2001-03-20',' XLS'),
(3,' File_4',' 2001-04-28',' TXT'),
(4,' File_5',' 2002-12-31',' DOC');
CREATE TABLE IF NOT NOT EXISTS files2000
(
id_file
mediumint(9)NOT NULL,
content
blob NOT NULL,
独特的钥匙id_file
(id_file
)
)ENGINE = MyISAM DEFAULT CHARSET = latin1;
INSERT INTO files2000
(id_file
,content
)VALUES
(1,0x636f6e74656e7431),
(2,0x636f6e74656e7432);
CREATE TABLE IF NOT NOT EXISTS files2001
(
id_file
mediumint(9)NOT NULL,
content
blob NOT NULL,
独特的钥匙id_file
(id_file
)
)ENGINE = MyISAM DEFAULT CHARSET = latin1;
INSERT INTO files2001
(id_file
,content
)VALUES
(3,0x636f6e74656e7433),
(4,0x636f6e74656e7434);
CREATE TABLE IF NOT NOT EXISTS files2002
(
id_file
mediumint(9)NOT NULL,
content
blob NOT NULL,
独特的钥匙id_file
(id_file
)
)ENGINE = MyISAM DEFAULT CHARSET = latin1;
INSERT INTO files2002
(id_file
,content
)VALUES
(5,0x636f6e74656e7435);
答案 0 :(得分:0)
一个可能非常慢的查询是:
select
f.*,
c.content
from
files f
inner join
(select id_file, content from files2000 union all
select id_file, content from files2001 union all
...
select id_file, content from files2013 union all
select id_file, content from files2014) c on c.id_file = f.id_file
where
f.extension = 'exe' and
f.date between ... and ... and
c.content like '%search string%'
但您必须每年更新此查询。您应该考虑将所有内容放在一个表中,或者如果您为了性能而执行此操作,那么最近会有一个内容。桌子和一个档案'表