| 1 | package DBIO::Oracle::Introspect::Indexes; | ||||||||||||||||||||||||
| 2 | # ABSTRACT: Introspect Oracle indexes | ||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||
| 4 | 27 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 27 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||
| 7 | 27 | our $VERSION = '0.900004'; | |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||
| 11 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||
|
Subroutine
fetch: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||
| 12 | 0 | my ($class, $dbh, $schema, $tables) = @_; | |||||||||||||||||||||||
| 13 | 0 | my %indexes; | |||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||
| 15 | # Fetch all indexes excluding those backing constraints (index_name != constraint_name) | ||||||||||||||||||||||||
| 16 | 0 | my $idx_sth = $dbh->prepare_cached(q{ | |||||||||||||||||||||||
| 17 | SELECT i.index_name, i.uniqueness, i.index_type, | ||||||||||||||||||||||||
| 18 | i.table_name, ic.column_name, ic.column_position | ||||||||||||||||||||||||
| 19 | FROM all_indexes i | ||||||||||||||||||||||||
| 20 | JOIN all_ind_columns ic | ||||||||||||||||||||||||
| 21 | ON i.index_name = ic.index_name | ||||||||||||||||||||||||
| 22 | AND i.table_name = ic.table_name | ||||||||||||||||||||||||
| 23 | AND i.owner = ic.index_owner | ||||||||||||||||||||||||
| 24 | WHERE i.table_owner = ? | ||||||||||||||||||||||||
| 25 | AND i.index_name NOT IN ( | ||||||||||||||||||||||||
| 26 | SELECT constraint_name FROM all_constraints | ||||||||||||||||||||||||
| 27 | WHERE owner = ? AND constraint_type IN ('P', 'U') | ||||||||||||||||||||||||
| 28 | ) | ||||||||||||||||||||||||
| 29 | ORDER BY i.table_name, i.index_name, ic.column_position | ||||||||||||||||||||||||
| 30 | }); | ||||||||||||||||||||||||
| 31 | 0 | $idx_sth->execute($schema, $schema); | |||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||
| 33 | 0 | ▶ | while (my $row = $idx_sth->fetchrow_hashref('NAME_lc')) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 34 | 0 | my $tbl = $row->{table_name}; | |||||||||||||||||||||||
| 35 | 0 | my $idx = $row->{index_name}; | |||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||
| 37 | 0 | push @{ $indexes{$tbl}{$idx}{columns} }, $row->{column_name}; | |||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||
| 39 | 0 | ▶ | $indexes{$tbl}{$idx}{index_name} //= $row->{index_name}; | ||||||||||||||||||||||
|
Condition0%0/3
$indexes{$tbl}{$idx}{"index_name"} //= $row->{"index_name"}
MC/DC0%0/2
$indexes{$tbl}{$idx}{"index_name"} //= $row->{"index_name"}
$indexes{$tbl}{$idx}{"index_name"}
$row->{"index_name"}
Truth table0%0/3
A //= B
A= $indexes{$tbl}{$idx}{"index_name"}B= $row->{"index_name"}
| |||||||||||||||||||||||||
| 40 | $indexes{$tbl}{$idx}{is_unique} //= | ||||||||||||||||||||||||
| 41 | 0 | ▶ | (lc($row->{uniqueness} // '') eq 'unique') ? 1 : 0; | ||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$indexes{$tbl}{$idx}{"is_unique"} //= lc($row->{"uniqueness"} // "") eq "unique" ? 1 : 0
$row->{"uniqueness"} // ""
MC/DC0%0/1
$indexes{$tbl}{$idx}{"is_unique"} //= lc($row->{"uniqueness"} // "") eq "unique" ? 1 : 0
$indexes{$tbl}{$idx}{"is_unique"}
Truth table0%0/2
A
A= $indexes{$tbl}{$idx}{"is_unique"}
| |||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||
| 43 | 0 | $idx_sth->finish; | |||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||
| 45 | # Ensure all tables exist in result even if no indexes | ||||||||||||||||||||||||
| 46 | 0 | for my $tbl (keys %$tables) { | |||||||||||||||||||||||
| 47 | 0 | ▶ | $indexes{$tbl} //= {}; | ||||||||||||||||||||||
|
Condition0%0/2
$indexes{$tbl} //= {}
MC/DC0%0/1
$indexes{$tbl} //= {}
$indexes{$tbl}
Truth table0%0/2
A
A= $indexes{$tbl}
| |||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||
| 50 | 0 | return \%indexes; | |||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | 27 | 1; | |||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||