我知道我无法从索引中删除行,我只能从实时索引中删除行。但是我必须从索引中删除行,但是现在不知道如何做。因此,这是我的表和记录:
+------+------+--------+
| id | name | status |
+------+------+--------+
| 1 | aaa | 1 |
| 2 | bbb | 1 |
| 3 | ccc | 1 |
+------+------+--------+
这是我的狮身人面像配置:
source mainSourse : mainConfSourse
{
sql_query = \
SELECT id, name, status \
from test_table
sql_field_string = name
sql_attr_uint = status
}
index testIndex
{
source = mainSourse
path = C:/sphinx/data/test/testIndex
morphology = stem_enru
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F, U+401->U+0435, U+451->U+0435
min_prefix_len = 3
index_exact_words = 1
expand_keywords = 1
}
index testIndexRT
{
type = rt
path = C:/sphinx/data/test/testIndexRT
rt_field = name
rt_attr_string = name
rt_attr_uint = status
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F, U+401->U+0435, U+451->U+0435
min_prefix_len = 3
index_exact_words = 1
expand_keywords = 1
}
启动狮身人面像服务器后,如果我想从testIndex更新记录,只需将新记录写入testIndexRT示例:
insert into testIndexRT (id,name,status) values (1,'aaa_updated',1);
然后该请求select * from testIndex,testIndexRT where status=1;
显示给我:
+------+-------------+--------+
| id | name | status |
+------+-------------+--------+
| 1 | aaa_updated | 1 |
| 2 | bbb | 1 |
| 3 | ccc | 1 |
+------+-------------+--------+
很好,太棒了!但是,当我想从索引中删除记录时,问题就开始了。我以为可以像更新一样使它变得容易,但是在此代码update testIndexRT set status=2 where id=1
之后,我看到:
+------+------+--------+
| id | name | status |
+------+------+--------+
| 1 | aaa | 1 |
| 2 | bbb | 1 |
| 3 | ccc | 1 |
+------+------+--------+
狮身人面像只是向我显示了来自testIndex的记录,尽管ID为1的行已在testIndexRT select * from testIndexRT;
中更新:
+------+--------+-------------+
| id | status | name |
+------+--------+-------------+
| 1 | 2 | aaa_updated |
+------+--------+-------------+
我意识到它的方法不起作用:(我无法将所有记录从数据库保存到testIndexRT,因为我的真实表很大,大小约为60 Gb。请告诉我,也许还有其他方法我不知道不知道吗?
60G对于RT索引应该不是问题,但是如果您要坚持使用普通索引,则可以使用main + delta技术来实现所需的目标。这是一个有关https://play.manticoresearch.com/maindelta/的交互式课程(它基于Manticore Search,后者是Sphinx的分支,但在Sphinx中应该完全一样,只是killlist_target在Sphinx 3中的命名有所不同)。
这里是另一个示例:
MySQL:
mysql> desc data;
+---------+------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------+------+-----+-------------------+-----------------------------+
| id | bigint(20) | NO | PRI | 0 | |
| body | text | YES | | NULL | |
| updated | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+---------+------------+------+-----+-------------------+-----------------------------+
3 rows in set (0.00 sec)
mysql> desc helper;
+----------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+-------------------+-----------------------------+
| chunk_id | varchar(255) | NO | PRI | | |
| built | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+----------+--------------+------+-----+-------------------+-----------------------------+
2 rows in set (0.00 sec)
配置:
source main
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = test
sql_query_pre = replace into helper set chunk_id = '1_tmp', built = now()
sql_query = select id, body, unix_timestamp(updated) updated from data where updated >= from_unixtime($start) and updated <= from_unixtime($end)
sql_query_range = select (select unix_timestamp(min(updated)) from data) min, (select unix_timestamp(built) - 1 from helper where chunk_id = '1_tmp') max
sql_query_post_index = replace into helper set chunk_id = '1', built = (select built from helper t where chunk_id = '1_tmp')
sql_range_step = 100
sql_field_string = body
sql_attr_timestamp = updated
}
source delta : main
{
sql_query_pre =
sql_query_range = select (select unix_timestamp(built) from helper where chunk_id = '1') min, unix_timestamp() max
sql_query_killlist = select id from data where updated >= (select built from helper where chunk_id = '1')
killlist_target = idx_main:kl
}
index idx
{
type = distributed
local = idx_main
local = idx_delta
}