| 1 | package DBIO::Oracle::Introspect::Indexes; | ||||||||||||||||||||||||
| 2 | # ABSTRACT: Introspect Oracle indexes | ||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||
| 4 | 29 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 29 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||
| 7 | 29 | our $VERSION = '0.900007'; | |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||
| 11 | 1 | ▶ | sub fetch { | ||||||||||||||||||||||
|
Subroutine
fetch: called CC=8 SCAR=31.1
Pod
documented
| |||||||||||||||||||||||||
| 12 | 1 | my ($class, $dbh, $schema, $tables) = @_; | |||||||||||||||||||||||
| 13 | 1 | my %indexes; | |||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||
| 15 | # Fetch all indexes excluding those backing constraints (index_name != constraint_name) | ||||||||||||||||||||||||
| 16 | 1 | 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 NLSSORT(i.table_name, 'NLS_SORT=BINARY'), | ||||||||||||||||||||||||
| 30 | NLSSORT(i.index_name, 'NLS_SORT=BINARY'), ic.column_position | ||||||||||||||||||||||||
| 31 | }); | ||||||||||||||||||||||||
| 32 | 1 | $idx_sth->execute($schema, $schema); | |||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||
| 34 | 1 | ▶ | while (my $row = $idx_sth->fetchrow_hashref('NAME_lc')) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 35 | 0 | my $tbl = $row->{table_name}; | |||||||||||||||||||||||
| 36 | 0 | my $idx = $row->{index_name}; | |||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||
| 38 | 0 | push @{ $indexes{$tbl}{$idx}{columns} }, $row->{column_name}; | |||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||
| 40 | 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"}
| |||||||||||||||||||||||||
| 41 | $indexes{$tbl}{$idx}{is_unique} //= | ||||||||||||||||||||||||
| 42 | 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"}
| |||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||
| 44 | 1 | $idx_sth->finish; | |||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||
| 46 | # Ensure all tables exist in result even if no indexes | ||||||||||||||||||||||||
| 47 | 1 | for my $tbl (keys %$tables) { | |||||||||||||||||||||||
| 48 | 1 | ▶ | $indexes{$tbl} //= {}; | ||||||||||||||||||||||
|
Condition50%1/2
$indexes{$tbl} //= {}
MC/DC0%0/1
$indexes{$tbl} //= {}
$indexes{$tbl}
Truth table50%1/2
A
A= $indexes{$tbl}
| |||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||
| 51 | 1 | return \%indexes; | |||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||
| 54 | 29 | 1; | |||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||