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;
+}
+
sub pg_insert {
my ( $self, $table, $h ) = @_;
$create_table = qq{
create table $part () inherits ($table) ;
};
+ $create_table .= $self->_create_index( $table, $timestamp );
$table = $part;
warn "# using partition $table";
}
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More tests => 17;
use Data::Dump qw(dump);
use lib 'lib';
ok my $o = APKPM::Store->new, 'new';
+ok my $sql = $o->_create_index('dslam', '2012_04_20'), '_create_index';
+diag $sql;
+
ok my $r = $o->insert('job',{
_table => 'ping',
ip => '127.0.0.1',