Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 86030
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: CAPTTOFU [...] cpan.org
Requestors: DDICK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 4.029



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;
corrected patch
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 18:43:32.732303524 +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; @@ -753,7 +815,7 @@ } BEGIN { - my @needs_async_check = qw/data_sources statistics_info quote_identifier begin_work/; + my @needs_async_check = qw/data_sources quote_identifier begin_work/; foreach my $method (@needs_async_check) { no strict 'refs';
Thank you! Adding this now. Sorry for the delay. On Mon Jun 10 04:00:19 2013, DDICK wrote: Show quoted text
> The attached patch adds support for statistics_info, to retrieve all > the indexes on a table
This was added in 4.029, closing!
On Mon Jan 26 03:02:04 2015, MICHIELB wrote: Show quoted text
> This was added in 4.029, closing!
Well that's weird. Given that 1) i wrote the patch 2) it looks as if it applied cleanly 3) it was credited in the Changelog why was the patch credited to someone called Milan Šorm?
RT-Send-CC: CAPTTOFU [...] cpan.org
Hi! On Sun Jan 25 14:22:12 2015, DDICK wrote: Show quoted text
> On Mon Jan 26 03:02:04 2015, MICHIELB wrote:
> > This was added in 4.029, closing!
> > Well that's weird. Given that > > 1) i wrote the patch > 2) it looks as if it applied cleanly > 3) it was credited in the Changelog > > why was the patch credited to someone called Milan Šorm?
I think this was plain oversight? Patrick, you applied the patch. Can you fill in? -- Michiel
Very sorry about this! I think what happened is Milan had a patch for something similar and in your case, I applied the patch and committed it in git and incorrectly identified the contributor. I'll give correct attribution in this upcoming release. Again, very sorry for the oversight. I appreciate greatly your contribution! Patrick On Sun Jan 25 15:03:16 2015, MICHIELB wrote: Show quoted text
> Hi! > > On Sun Jan 25 14:22:12 2015, DDICK wrote:
> > On Mon Jan 26 03:02:04 2015, MICHIELB wrote:
> > > This was added in 4.029, closing!
> > > > Well that's weird. Given that > > > > 1) i wrote the patch > > 2) it looks as if it applied cleanly > > 3) it was credited in the Changelog > > > > why was the patch credited to someone called Milan Šorm?
> > I think this was plain oversight? > Patrick, you applied the patch. Can you fill in? > > -- > Michiel
No problems. Sounds a good solution to me! On Wed Jan 28 14:18:17 2015, CAPTTOFU wrote: Show quoted text
> Very sorry about this! > > I think what happened is Milan had a patch for something similar and > in your case, I applied the patch and committed it in git and > incorrectly identified the contributor. > > I'll give correct attribution in this upcoming release. > > Again, very sorry for the oversight. I appreciate greatly your > contribution! > > Patrick > > On Sun Jan 25 15:03:16 2015, MICHIELB wrote:
> > Hi! > > > > On Sun Jan 25 14:22:12 2015, DDICK wrote:
> > > On Mon Jan 26 03:02:04 2015, MICHIELB wrote:
> > > > This was added in 4.029, closing!
> > > > > > Well that's weird. Given that > > > > > > 1) i wrote the patch > > > 2) it looks as if it applied cleanly > > > 3) it was credited in the Changelog > > > > > > why was the patch credited to someone called Milan Šorm?
> > > > I think this was plain oversight? > > Patrick, you applied the patch. Can you fill in? > > > > -- > > Michiel