我有一个名为 tuples 的 sqlite 表,定义如下
create table tuples
(
a INTEGER not null,
b INTEGER not null,
c INTEGER not null,
d INTEGER not null,
primary key (a, b, c, d)
) without rowid;
Run Code Online (Sandbox Code Playgroud)
充满了数百万个独特的元组 (>1TB)。新元组经常被插入,带有“随机”值。仅在极少数情况下才会删除行。
对于访问数据库的外部进程,我需要在表中找到“下一个”或“上一个”现有的 4 元组。
例如:给定元组 (1-1-1-1)、(1-1-1-4) 和 (1-2-3-4),对于元组 (1-1-1-3)(不需要存在于表中)“下一个”元素是(1-1-1-4),前一个是(1-1-1-1)(两者都需要存在)。因为 (1-1-1-4) (1-2-3-4) 是“下一个”元素。Corner-case:如果实际上没有“next”或“previous”元素,则结果允许为空。(1-2-3-4) 没有“下一个”元素。
目前我试图找到下一个元组 ("center" is (1-1-1-3))
select a,b,c,d from tuple
where (a == 1 AND b == 1 AND c == 1 AND d > 3) OR
(a == 1 AND b == 1 …
Run Code Online (Sandbox Code Playgroud)