|
本帖最后由 〇〇 于 2022-11-21 12:59 编辑
30不是底,sqlite 3.40
.timer on
with recursive t1 as(select '1' n union all select '2'),
t3 as(select t1.n||t1a.n||t1b.n s from t1,t1 t1a,t1 t1b),
t as(select 1 lv, t3.s from t3
union all
select lv+1, t.s||t1.n str from t,t1 where not exists(select 1 from --t3 a,
(select value c from generate_series(1,30))c,
(select value d from generate_series(1,30))d
where --求一个字符串s所有长度>=3的子串
length(substr(s,c,d))>=3
and c<=length(s)
and c+d<=length(s)+1
--从子串的下一位开始比较
and instr(substr(t.s||t1.n,c+1),substr(s,c,d)) between 1 and length(substr(s,c,d))
)and lv<=30)
select max(length(s)) from t;
33
Run Time : real 229.472 user 229.321470 sys 0.000000
--duckdb 0.6.0
with recursive t1 as(select n from (values('1'),('2'))t(n)),
t3 as(select t1.n||t1a.n||t1b.n s from t1,t1 t1a,t1 t1b),
t as(select 1 lv, t3.s from t3
union all
select lv+1, t.s||t1.n str from t,t1 where not exists(select 1 from --t3 a,
(select c from generate_series(1,30)c(c)),
(select d from generate_series(1,30)d(d))
where --求一个字符串s所有长度>=3的子串
length(substr(s,c,d))>=3
and c<=length(s)
and c+d<=length(s)+1
--从子串的下一位开始比较
and instr(substr(t.s||t1.n,c+1),substr(s,c,d)) between 1 and length(substr(s,c,d))
)and lv<=30)
select s from t where length(s)=33;
┌───────────────────────────────────┐
│ s │
│ varchar │
├───────────────────────────────────┤
│ 221211221112221211122121122111211 │
│ 211121221112221211122121122111211 │
│ 221121221112221211122121122111211 │
│ 111212221112221211122121122111211 │
│ 211212221112221211122121122111211 │
│ 121112212112221211122121122111211 │
│ 221112212112221211122121122111211 │
│ 222112212112221211122121122111211 │
│ 121112122112221211122121122111211 │
│ 221112122112221211122121122111211 │
│ · │
│ · │
│ · │
│ 221121222111221121222121122211212 │
│ 211122121112221121222121122211212 │
│ 121122121112221121222121122211212 │
│ 221122121112221121222121122211212 │
│ 111222121112221121222121122211212 │
│ 211222121112221121222121122211212 │
│ 121222121112221121222121122211212 │
│ 221211221112221121222121122211212 │
│ 211121221112221121222121122211212 │
│ 221121221112221121222121122211212 │
├───────────────────────────────────┤
│ 50568 rows (20 shown) │
└───────────────────────────────────┘
Run Time (s): real 42.219 user 50.263522 sys 0.296402
|
|