Oracle/Introspect/Indexes.pm

filter: Statementstmt 31.8% 7 / 22 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 22.2% 10 / 45 CC 8 SCAR 40.6
CC
8
Cov
19%
fetch
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 57.8
« Oracle/Introspect/ForeignKeys.pm ↑ Summary Oracle/Introspect/Keys.pm »
1 package DBIO::Oracle::Introspect::Indexes;
2 # ABSTRACT: Introspect Oracle indexes
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8  
9 0 ▶sub fetch {
Subroutine fetch: not called CC=8 SCAR=42.8
Pod documented
10 0 my ($class, $dbh, $schema, $tables) = @_;
11 0 my %indexes;
12  
13 # Fetch all indexes excluding those backing constraints (index_name != constraint_name)
14 0 my $idx_sth = $dbh->prepare_cached(q{
15 SELECT i.index_name, i.uniqueness, i.index_type,
16 i.table_name, ic.column_name, ic.column_position
17 FROM all_indexes i
18 JOIN all_ind_columns ic
19 ON i.index_name = ic.index_name
20 AND i.table_name = ic.table_name
21 AND i.owner = ic.index_owner
22 WHERE i.table_owner = ?
23 AND i.index_name NOT IN (
24 SELECT constraint_name FROM all_constraints
25 WHERE owner = ? AND constraint_type IN ('P', 'U')
26 )
27 ORDER BY i.table_name, i.index_name, ic.column_position
28 });
29 0 $idx_sth->execute($schema, $schema);
30  
31 0 ▶ while (my $row = $idx_sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $idx_sth->fetchrow_hashref) 0 0 0
32 0 my $tbl = $row->{table_name};
33 0 my $idx = $row->{index_name};
34  
35 0 push @{ $indexes{$tbl}{$idx}{columns} }, $row->{column_name};
36  
37 0 ▶ $indexes{$tbl}{$idx}{index_name} //= $row->{index_name};
Condition0%0/3
$indexes{$tbl}{$idx}{"index_name"} //= $row->{"index_name"}
l!l&&r!l&&!r
000
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"}
ABresult
1X1
011
000
38 $indexes{$tbl}{$idx}{is_unique} //=
39 0 ▶ (lc($row->{uniqueness} // '') eq 'unique') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
lc($row->{'uniqueness'} // '') eq 'unique' ? : 0 0 0
Condition0%0/5
$indexes{$tbl}{$idx}{"is_unique"} //= lc($row->{"uniqueness"} // "") eq "unique" ? 1 : 0
l!l&&r!l&&!r
000
$row->{"uniqueness"} // ""
l!l
00
MC/DC0%0/2
$indexes{$tbl}{$idx}{"is_unique"} //= lc($row->{"uniqueness"} // "") eq "unique" ? 1 : 0
$indexes{$tbl}{$idx}{"is_unique"} $row->{"uniqueness"}
Truth table0%0/3
A //= B
A= $indexes{$tbl}{$idx}{"is_unique"}B= $row->{"uniqueness"}
ABresult
1X1
011
000
40 }
41 0 $idx_sth->finish;
42  
43 # Ensure all tables exist in result even if no indexes
44 0 for my $tbl (keys %$tables) {
45 0 ▶ $indexes{$tbl} //= {};
Condition0%0/2
$indexes{$tbl} //= {}
l!l
00
MC/DC0%0/1
$indexes{$tbl} //= {}
$indexes{$tbl}
Truth table0%0/2
A
A= $indexes{$tbl}
Aresult
11
00
46 }
47  
48 0 return \%indexes;
49 }
50  
51 1 1;
52  
53 __END__
54  
55 =pod
56  
57 =encoding UTF-8
58  
59 =head1 NAME
60  
61 DBIO::Oracle::Introspect::Indexes - Introspect Oracle indexes
62  
63 =head1 VERSION
64  
65 version 0.900001
66  
67 =head1 DESCRIPTION
68  
69 Fetches Oracle index metadata via C<all_indexes> and C<all_ind_columns>.
70 Explicit indexes are returned (not auto-generated PK/UK indexes).
71  
72 =head1 METHODS
73  
74 =head2 fetch
75  
76 my $indexes = DBIO::Oracle::Introspect::Indexes->fetch($dbh, $schema, $tables);
77  
78 Returns a hashref keyed by table name, each value a hashref keyed by
79 index name with: C<index_name>, C<is_unique>, C<columns> (arrayref).
80  
81 =head1 AUTHOR
82  
83 DBIO & DBIx::Class Authors
84  
85 =head1 COPYRIGHT AND LICENSE
86  
87 Copyright (C) 2026 DBIO Authors
88 Portions Copyright (C) 2005-2025 DBIx::Class Authors
89 Based on DBIx::Class, heavily modified.
90  
91 This is free software; you can redistribute it and/or modify it under
92 the same terms as the Perl 5 programming language system itself.
93  
94 =cut
« Oracle/Introspect/ForeignKeys.pm ↑ Summary Oracle/Introspect/Keys.pm »