create table t(a integer, b text); with recursive c(x) as (select 1 union all select x + 1 from c where x < 1000) insert into t select x, 'r' || x from c; create index tb on t(b); select count(*), sum(a), max(b) from t where a % 3 = 0;