Subject: | PATCH: adding statistics_info support |
The attached patch adds support for statistics_info, to retrieve all the indexes on a table
Subject: | dbd_mysql_info.patch |
diff -Naur old/lib/DBD/mysql.pm new/lib/DBD/mysql.pm
--- old/lib/DBD/mysql.pm 2011-08-21 04:39:24.000000000 +1000
+++ new/lib/DBD/mysql.pm 2013-06-10 17:52:57.027334682 +1000
@@ -728,6 +728,68 @@
return $sth;
}
+sub statistics_info {
+ my ($dbh,
+ $catalog, $schema, $table,
+ $unique_only, $quick,
+ ) = @_;
+
+ return unless $dbh->func('_async_check');
+
+ # INFORMATION_SCHEMA.KEY_COLUMN_USAGE was added in 5.0.6
+ # no one is going to be running 5.0.6, taking out the check for $point > .6
+ my ($maj, $min, $point) = _version($dbh);
+ return if $maj < 5 ;
+
+ my $sql = <<'EOF';
+SELECT TABLE_CATALOG AS TABLE_CAT,
+ TABLE_SCHEMA AS TABLE_SCHEM,
+ TABLE_NAME AS TABLE_NAME,
+ NON_UNIQUE AS NON_UNIQUE,
+ NULL AS INDEX_QUALIFIER,
+ INDEX_NAME AS INDEX_NAME,
+ LCASE(INDEX_TYPE) AS TYPE,
+ SEQ_IN_INDEX AS ORDINAL_POSITION,
+ COLUMN_NAME AS COLUMN_NAME,
+ COLLATION AS ASC_OR_DESC,
+ CARDINALITY AS CARDINALITY,
+ NULL AS PAGES,
+ NULL AS FILTER_CONDITION
+ FROM INFORMATION_SCHEMA.STATISTICS
+EOF
+
+ my @where;
+ my @bind;
+
+ # catalogs are not yet supported by MySQL
+
+# if (defined $catalog) {
+# push @where, 'TABLE_CATALOG = ?';
+# push @bind, $catalog;
+# }
+
+ if (defined $schema) {
+ push @where, 'TABLE_SCHEMA = ?';
+ push @bind, $schema;
+ }
+
+ if (defined $table) {
+ push @where, 'TABLE_NAME = ?';
+ push @bind, $table;
+ }
+
+ if (@where) {
+ $sql .= ' WHERE ';
+ $sql .= join ' AND ', @where;
+ }
+ $sql .= " ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION";
+
+ local $dbh->{FetchHashKeyName} = 'NAME_uc';
+ my $sth = $dbh->prepare($sql);
+ $sth->execute(@bind);
+
+ return $sth;
+}
sub _version {
my $dbh = shift;