| 1 | package DBIO::ClickHouse::Introspect::Indexes; | ||||||||||||
| 2 | # ABSTRACT: Introspect ClickHouse data-skipping indexes via system.data_skipping_indices | ||||||||||||
| 3 | |||||||||||||
| 4 | 34 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 34 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 34 | our $VERSION = '0.900007'; | |||||||||||
| 8 | |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | 2 | ▶ | sub fetch { | ||||||||||
|
Subroutine
fetch: called CC=7 SCAR=20.1
Pod
documented
| |||||||||||||
| 12 | 2 | my ($class, $dbh, $tables, $database) = @_; | |||||||||||
| 13 | |||||||||||||
| 14 | 2 | my $sql = q{ | |||||||||||
| 15 | SELECT | ||||||||||||
| 16 | table, | ||||||||||||
| 17 | name, | ||||||||||||
| 18 | type, | ||||||||||||
| 19 | type_full, | ||||||||||||
| 20 | expr, | ||||||||||||
| 21 | granularity | ||||||||||||
| 22 | FROM system.data_skipping_indices | ||||||||||||
| 23 | WHERE database = %s | ||||||||||||
| 24 | ORDER BY table, name | ||||||||||||
| 25 | }; | ||||||||||||
| 26 | 2 | my @bind; | |||||||||||
| 27 | 2 | ▶ | if (defined $database) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 0 | $sql = sprintf $sql, '?'; | |||||||||||
| 29 | 0 | push @bind, $database; | |||||||||||
| 30 | } | ||||||||||||
| 31 | else { | ||||||||||||
| 32 | 2 | $sql = sprintf $sql, 'currentDatabase()'; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | 2 | my %indexes; | |||||||||||
| 36 | |||||||||||||
| 37 | 2 | ▶ | my $sth = eval { my $s = $dbh->prepare($sql); $s->execute(@bind); $s } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | or return \%indexes; | ||||||||||||
| 39 | |||||||||||||
| 40 | 1 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 1 | ▶ | my $table = $row->{table} // ''; | ||||||||||
|
Condition50%1/2
$row->{"table"} // ""
MC/DC0%0/1
$row->{"table"} // ""
$row->{"table"}
Truth table50%1/2
A
A= $row->{"table"}
| |||||||||||||
| 42 | 1 | ▶ | next unless exists $tables->{$table}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | |||||||||||||
| 44 | $indexes{$table}{ $row->{name} } = { | ||||||||||||
| 45 | index_name => $row->{name}, | ||||||||||||
| 46 | expr => $row->{expr}, | ||||||||||||
| 47 | type => $row->{type}, | ||||||||||||
| 48 | type_full => $row->{type_full}, | ||||||||||||
| 49 | granularity => defined $row->{granularity} ? 0 + $row->{granularity} : undef, | ||||||||||||
| 50 | 1 | ▶ | }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | 1 | return \%indexes; | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | 34 | 1; | |||||||||||
| 58 | |||||||||||||
| 59 | __END__ | ||||||||||||