+our $redis;
+sub redis { $redis ||= Redis->new };
+
+sub _create_index {
+ my ( $self, $table, $timestamp ) = @_;
+
+ my $sth = $self->dbh->prepare( qq{
+
+select
+ t.relname as table_name,
+ i.relname as index_name,
+ a.attname as column_name
+from
+ pg_class t,
+ pg_class i,
+ pg_index ix,
+ pg_attribute a
+where
+ t.oid = ix.indrelid
+ and i.oid = ix.indexrelid
+ and a.attrelid = t.oid
+ and a.attnum = ANY(ix.indkey)
+ and t.relkind = 'r'
+ and t.relname like ?
+order by
+ t.relname,
+ i.relname;
+
+ } );
+ $sth->execute($table);
+ my $sql = '';
+ while( my $row = $sth->fetchrow_hashref ) {
+ #warn "# _create_index $table ",dump($row);
+ $sql .= qq|create index $row->{index_name}_$timestamp on ${table}_$timestamp($row->{column_name});\n|;
+ }
+
+ return $sql;
+}
+