Firebird/Introspect/Indexes.pm

filter: Statementstmt 20.5% 7 / 34 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 19.6% 10 / 51 CC 8 SCAR 40.6
CC
8
Cov
15%
fetch
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 57.8
« Firebird/Introspect/Columns.pm ↑ Summary Firebird/Storage/Common.pm »
1 package DBIO::Firebird::Introspect::Indexes;
2 # ABSTRACT: Introspect Firebird indexes via rdb$indices / rdb$index_segments
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶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, $tables) = @_;
11 0 my %indexes;
12  
13 0 my $sth = $dbh->prepare(q{
14 SELECT i.rdb$index_name, i.rdb$relation_name, i.rdb$unique_flag,
15 iseg.rdb$field_name, iseg.rdb$field_position,
16 i.rdb$index_type
17 FROM rdb$indices i
18 JOIN rdb$index_segments iseg ON i.rdb$index_name = iseg.rdb$index_name
19 WHERE i.rdb$system_flag = 0
20 AND i.rdb$foreign_key IS NULL
21 ORDER BY i.rdb$relation_name, i.rdb$index_name, iseg.rdb$field_position
22 });
23 0 $sth->execute;
24  
25 0 my %idx_info;
26 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
27 0 my $table = $row->{'rdb$relation_name'};
28 0 $table =~ s/\s+$//;
29 0 ▶ next unless exists $tables->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tables->{$table} 0 0 0
30  
31 0 my $name = $row->{'rdb$index_name'};
32 0 $name =~ s/\s+$//;
33  
34 $idx_info{$name} //= {
35 index_name => $name,
36 table_name => $table,
37 0 ▶ is_unique => $row->{'rdb$unique_flag'} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$row->{'rdb$unique_flag'} ? : 0 0 0
Condition0%0/2
$idx_info{$name} //= {"index_name", $name, "table_name", $table, "is_unique", $row->{"rdb\$unique_flag"} ? 1 : 0, "columns", []}
l!l
00
MC/DC0%0/1
$idx_info{$name} //= {"index_name", $name, "table_name", $table, "is_unique", $row->{"rdb\$unique_flag"} ? 1 : 0, "columns", []}
$idx_info{$name}
Truth table0%0/2
A
A= $idx_info{$name}
Aresult
11
00
38 columns => [],
39 };
40  
41 0 my $col = $row->{'rdb$field_name'};
42 0 $col =~ s/\s+$//;
43 0 push @{ $idx_info{$name}{columns} }, $col;
44 }
45  
46 # Filter out PK/UNIQUE-backed indexes by checking rdb$relation_constraints
47 0 my $constr_sth = $dbh->prepare(q{
48 SELECT ix.rdb$index_name
49 FROM rdb$relation_constraints rc
50 JOIN rdb$indices ix ON rc.rdb$index_name = ix.rdb$index_name
51 WHERE rc.rdb$constraint_type IN ('PRIMARY KEY', 'UNIQUE')
52 });
53 0 $constr_sth->execute;
54 0 my %skip_idx;
55 0 ▶ while (my ($idx) = $constr_sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($idx) = $constr_sth->fetchrow_array) 0 0 0
56 0 $idx =~ s/\s+$//;
57 0 $skip_idx{$idx} = 1;
58 }
59  
60 0 for my $name (sort keys %idx_info) {
61 0 ▶ next if $skip_idx{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $skip_idx{$name} 0 0 0
62 0 my $info = $idx_info{$name};
63 $indexes{ $info->{table_name} }{ $name } = {
64 index_name => $name,
65 is_unique => $info->{is_unique},
66 columns => $info->{columns},
67 0 };
68 }
69  
70 0 return \%indexes;
71 }
72  
73 3 1;
74  
75 __END__
76  
77 =pod
78  
79 =encoding UTF-8
80  
81 =head1 NAME
82  
83 DBIO::Firebird::Introspect::Indexes - Introspect Firebird indexes via rdb$indices / rdb$index_segments
84  
85 =head1 VERSION
86  
87 version 0.900001
88  
89 =head1 DESCRIPTION
90  
91 Fetches index metadata via C<rdb$indices> joined against C<rdb$index_segments>.
92 Primary-key and unique-constraint indexes are filtered out -- they belong
93 to the table definition, not explicit CREATE INDEX.
94  
95 =head1 METHODS
96  
97 =head2 fetch
98  
99 my $indexes = DBIO::Firebird::Introspect::Indexes->fetch($dbh, $tables);
100  
101 Returns a hashref keyed by table name, each value a hashref keyed by
102 index name with: C<index_name>, C<is_unique>, C<columns> (arrayref).
103  
104 =head1 AUTHOR
105  
106 DBIO & DBIx::Class Authors
107  
108 =head1 COPYRIGHT AND LICENSE
109  
110 Copyright (C) 2026 DBIO Authors
111 Portions Copyright (C) 2005-2025 DBIx::Class Authors
112 Based on DBIx::Class, heavily modified.
113  
114 This is free software; you can redistribute it and/or modify it under
115 the same terms as the Perl 5 programming language system itself.
116  
117 =cut
« Firebird/Introspect/Columns.pm ↑ Summary Firebird/Storage/Common.pm »