<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: DBA_OBJECTS View for MySQL</title>
	<atom:link href="http://www.pythian.com/news/1488/dba_objects-view-for-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pythian.com/news/1488/dba_objects-view-for-mysql/</link>
	<description>News and views from Pythian DBAs</description>
	<lastBuildDate>Fri, 10 Feb 2012 13:01:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: ArtÃ­culos destacados, Febrero de 2009 &#124; cambrico.net</title>
		<link>http://www.pythian.com/news/1488/dba_objects-view-for-mysql/#comment-348986</link>
		<dc:creator>ArtÃ­culos destacados, Febrero de 2009 &#124; cambrico.net</dc:creator>
		<pubDate>Fri, 06 Mar 2009 12:31:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/1488/dba_objects-view-for-mysql#comment-348986</guid>
		<description>[...] DBA_OBJECTS para MySQL, en The Pythian Group. (en [...]</description>
		<content:encoded><![CDATA[<p>[...] DBA_OBJECTS para MySQL, en The Pythian Group. (en [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Gorbachev</title>
		<link>http://www.pythian.com/news/1488/dba_objects-view-for-mysql/#comment-346348</link>
		<dc:creator>Alex Gorbachev</dc:creator>
		<pubDate>Sat, 28 Feb 2009 08:05:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/1488/dba_objects-view-for-mysql#comment-346348</guid>
		<description>Brilliant idea. Makes Oracle DBA&#039;s life so much easier in MySQL world. :)</description>
		<content:encoded><![CDATA[<p>Brilliant idea. Makes Oracle DBA&#8217;s life so much easier in MySQL world. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Augusto Bott</title>
		<link>http://www.pythian.com/news/1488/dba_objects-view-for-mysql/#comment-344656</link>
		<dc:creator>Augusto Bott</dc:creator>
		<pubDate>Tue, 24 Feb 2009 18:10:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/1488/dba_objects-view-for-mysql#comment-344656</guid>
		<description>Updated the snippet on the &lt;a href=&quot;http://forge.mysql.com/tools/tool.php?id=179&quot; rel=&quot;nofollow&quot;&gt;MySQL Forge&lt;/a&gt; - ditched the &lt;code&gt;PROC&lt;/code&gt;. A newer version will be posted soon.

Cheers!</description>
		<content:encoded><![CDATA[<p>Updated the snippet on the <a href="http://forge.mysql.com/tools/tool.php?id=179" rel="nofollow">MySQL Forge</a> &#8211; ditched the <code>PROC</code>. A newer version will be posted soon.</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roland Bouman</title>
		<link>http://www.pythian.com/news/1488/dba_objects-view-for-mysql/#comment-342190</link>
		<dc:creator>Roland Bouman</dc:creator>
		<pubDate>Wed, 18 Feb 2009 09:56:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/1488/dba_objects-view-for-mysql#comment-342190</guid>
		<description>Augusto, thanks! 

kind regards,

Roland</description>
		<content:encoded><![CDATA[<p>Augusto, thanks! </p>
<p>kind regards,</p>
<p>Roland</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Augusto Bott</title>
		<link>http://www.pythian.com/news/1488/dba_objects-view-for-mysql/#comment-342057</link>
		<dc:creator>Augusto Bott</dc:creator>
		<pubDate>Wed, 18 Feb 2009 04:54:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/1488/dba_objects-view-for-mysql#comment-342057</guid>
		<description>@Roland,

Thanks for you feedback - it&#039;s much appreciated! I&#039;ll make sure we include the improvements you suggested in future posts/snippets.

Cheers!</description>
		<content:encoded><![CDATA[<p>@Roland,</p>
<p>Thanks for you feedback &#8211; it&#8217;s much appreciated! I&#8217;ll make sure we include the improvements you suggested in future posts/snippets.</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roland Bouman</title>
		<link>http://www.pythian.com/news/1488/dba_objects-view-for-mysql/#comment-341817</link>
		<dc:creator>Roland Bouman</dc:creator>
		<pubDate>Tue, 17 Feb 2009 20:21:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/1488/dba_objects-view-for-mysql#comment-341817</guid>
		<description>Hi there!

this is a nice idea but I think your implementation is flawed:

#1
the cursor really isn&#039;t necessary. You can get all this information using the information_schema.SCHEMATA system view. Also, a CURSOR on any SHOW statement is not supported (yes, I know it works...sometimes)

#2
You could simply create a view on these information schema tables instead of filling a temporary table. Although a view on the I_S tables will perform quite nicely provided you scan it once completely before using it, I can see some benefit of a using a table - however, your table is completely without indexes and does not even have a primary key. Really, if you are taking the trouble, why not create a nicely indexed structure?

#3
Currently, you are reporting VIEWS twice, once as table and once as view because you are doing separate queries on information_schema.TABLES and information_Schema.VIEWS. This is wrong and not necessary - you can simply query only information_schema.TABLES and use TABLE_TYPE instead of the constants &#039;table&#039; and &#039;view&#039;. As a bonus, you will correctly report information_schema tables as &#039;SYSTEM VIEW&#039;

#4
I don&#039;t think you are using KEY_COLUMN_USAGE correctly.I mean, this table contains one row for each *column* used in either a PRIMARY KEY constraint or FOREIGN KEY constraint. From your query the intention seems to be to report *indexes*. If you want indexes, you should do a GROUP BY on table_schema, table_name, index_name on the information_schema.STATISTICS table.

#5
You are using a UNION. If you fix #4, you can write the legs of the UNION query so that you only yield unique objects, and hence you could use UNION ALL which should matter performance-wise

#6 
You are not reporting all objects. I don&#039;t see plugins, triggers, stored procedures and events. These can all be fetched from the information_schema

#7 
if you are willing to include a dependency on the mysql database, you can even include UDFs.

Now, I know it&#039;s easy to bitch and all, so now I will contribute what I would feel more comfortable with:

CREATE OR REPLACE VIEW dba_objects (
  OBJECT_SCHEMA
, OBJECT_TYPE
, OBJECT_NAME
, OBJECT_COMMENT
, SUPER_OBJECT_SCHEMA
, SUPER_OBJECT_TYPE
, SUPER_OBJECT_NAME
) 
AS
SELECT SCHEMA_NAME
,      &#039;SCHEMA&#039;
,      SCHEMA_NAME
,      null
,      null
,      null
,      null
FROM   information_schema.SCHEMATA
UNION ALL
SELECT TABLE_SCHEMA
,      CONCAT(TABLE_TYPE, IF(TABLE_TYPE=&#039;BASE TABLE&#039;, CONCAT(&#039; (&#039;, ENGINE, &#039;)&#039;), &#039;&#039;))
,      TABLE_NAME
,      TABLE_COMMENT
,      TABLE_SCHEMA
,      &#039;SCHEMA&#039;
,      TABLE_SCHEMA
FROM   information_schema.TABLES
UNION ALL
SELECT CONSTRAINT_SCHEMA
,      CONCAT(CONSTRAINT_TYPE, &#039; CONSTRAINT&#039;)
,      CONSTRAINT_NAME
,      null
,      TABLE_SCHEMA
,      &#039;BASE TABLE&#039;
,      TABLE_NAME
FROM   information_schema.TABLE_CONSTRAINTS
UNION ALL
SELECT INDEX_SCHEMA
,      CONCAT(IF(NON_UNIQUE, &#039;&#039;, &#039;UNIQUE &#039;), INDEX_TYPE, &#039; &#039;, &#039;INDEX&#039;)
,      INDEX_NAME
,      COMMENT
,      TABLE_SCHEMA
,      &#039;BASE TABLE&#039;
,      TABLE_NAME
FROM   information_schema.STATISTICS
WHERE  SEQ_IN_INDEX = 1 -- report each index only once
UNION ALL
SELECT null
,      CONCAT(PLUGIN_TYPE, &#039; PLUGIN&#039;)
,      PLUGIN_NAME
,      PLUGIN_DESCRIPTION
,      null
,      &#039;library&#039;
,      PLUGIN_LIBRARY
FROM   information_schema.PLUGINS
UNION ALL
SELECT EVENT_SCHEMA
,      &#039;EVENT&#039;
,      EVENT_NAME
,      EVENT_COMMENT
,      EVENT_SCHEMA
,      &#039;SCHEMA&#039;
,      EVENT_SCHEMA
FROM   information_schema.EVENTS
UNION ALL 
SELECT TRIGGER_SCHEMA
,      CONCAT(ACTION_TIMING, &#039; &#039;, EVENT_MANIPULATION, &#039; &#039;, ACTION_ORIENTATION, &#039; TRIGGER&#039;)
,      TRIGGER_NAME
,      null
,      EVENT_OBJECT_SCHEMA
,      &#039;BASE TABLE&#039;
,      EVENT_OBJECT_TABLE
FROM   information_schema.TRIGGERS
UNION ALL 
SELECT ROUTINE_SCHEMA
,      ROUTINE_TYPE
,      ROUTINE_NAME
,      ROUTINE_COMMENT
,      ROUTINE_SCHEMA
,      &#039;SCHEMA&#039;
,      ROUTINE_SCHEMA
FROM   information_schema.ROUTINES

Caveats:

1) indexes and constraints are reported as separate objects - in MySQL there is physically no difference between f.e. a UNIQUE CONSTRAINT and the index that implements it - this view however reports them as separate objects.

2) this is a view on the information schema - it can be slow on the first run or when there are many many objects in the information schema

3) I don&#039;t include columns. It clutters he output and IMO they are not objects in themselves.

4) SUPER_OBJECT_SCHEMA always reports a SCHEMA if possible, even if the super object is itself a schema.

5) I excluded the user-defined functions to avoid a dependency on the mysql database.

kind regards,

Roland BOuman</description>
		<content:encoded><![CDATA[<p>Hi there!</p>
<p>this is a nice idea but I think your implementation is flawed:</p>
<p>#1<br />
the cursor really isn&#8217;t necessary. You can get all this information using the information_schema.SCHEMATA system view. Also, a CURSOR on any SHOW statement is not supported (yes, I know it works&#8230;sometimes)</p>
<p>#2<br />
You could simply create a view on these information schema tables instead of filling a temporary table. Although a view on the I_S tables will perform quite nicely provided you scan it once completely before using it, I can see some benefit of a using a table &#8211; however, your table is completely without indexes and does not even have a primary key. Really, if you are taking the trouble, why not create a nicely indexed structure?</p>
<p>#3<br />
Currently, you are reporting VIEWS twice, once as table and once as view because you are doing separate queries on information_schema.TABLES and information_Schema.VIEWS. This is wrong and not necessary &#8211; you can simply query only information_schema.TABLES and use TABLE_TYPE instead of the constants &#8216;table&#8217; and &#8216;view&#8217;. As a bonus, you will correctly report information_schema tables as &#8216;SYSTEM VIEW&#8217;</p>
<p>#4<br />
I don&#8217;t think you are using KEY_COLUMN_USAGE correctly.I mean, this table contains one row for each *column* used in either a PRIMARY KEY constraint or FOREIGN KEY constraint. From your query the intention seems to be to report *indexes*. If you want indexes, you should do a GROUP BY on table_schema, table_name, index_name on the information_schema.STATISTICS table.</p>
<p>#5<br />
You are using a UNION. If you fix #4, you can write the legs of the UNION query so that you only yield unique objects, and hence you could use UNION ALL which should matter performance-wise</p>
<p>#6<br />
You are not reporting all objects. I don&#8217;t see plugins, triggers, stored procedures and events. These can all be fetched from the information_schema</p>
<p>#7<br />
if you are willing to include a dependency on the mysql database, you can even include UDFs.</p>
<p>Now, I know it&#8217;s easy to bitch and all, so now I will contribute what I would feel more comfortable with:</p>
<p>CREATE OR REPLACE VIEW dba_objects (<br />
  OBJECT_SCHEMA<br />
, OBJECT_TYPE<br />
, OBJECT_NAME<br />
, OBJECT_COMMENT<br />
, SUPER_OBJECT_SCHEMA<br />
, SUPER_OBJECT_TYPE<br />
, SUPER_OBJECT_NAME<br />
)<br />
AS<br />
SELECT SCHEMA_NAME<br />
,      &#8216;SCHEMA&#8217;<br />
,      SCHEMA_NAME<br />
,      null<br />
,      null<br />
,      null<br />
,      null<br />
FROM   information_schema.SCHEMATA<br />
UNION ALL<br />
SELECT TABLE_SCHEMA<br />
,      CONCAT(TABLE_TYPE, IF(TABLE_TYPE=&#8217;BASE TABLE&#8217;, CONCAT(&#8216; (&#8216;, ENGINE, &#8216;)&#8217;), &#8221;))<br />
,      TABLE_NAME<br />
,      TABLE_COMMENT<br />
,      TABLE_SCHEMA<br />
,      &#8216;SCHEMA&#8217;<br />
,      TABLE_SCHEMA<br />
FROM   information_schema.TABLES<br />
UNION ALL<br />
SELECT CONSTRAINT_SCHEMA<br />
,      CONCAT(CONSTRAINT_TYPE, &#8216; CONSTRAINT&#8217;)<br />
,      CONSTRAINT_NAME<br />
,      null<br />
,      TABLE_SCHEMA<br />
,      &#8216;BASE TABLE&#8217;<br />
,      TABLE_NAME<br />
FROM   information_schema.TABLE_CONSTRAINTS<br />
UNION ALL<br />
SELECT INDEX_SCHEMA<br />
,      CONCAT(IF(NON_UNIQUE, &#8221;, &#8216;UNIQUE &#8216;), INDEX_TYPE, &#8216; &#8216;, &#8216;INDEX&#8217;)<br />
,      INDEX_NAME<br />
,      COMMENT<br />
,      TABLE_SCHEMA<br />
,      &#8216;BASE TABLE&#8217;<br />
,      TABLE_NAME<br />
FROM   information_schema.STATISTICS<br />
WHERE  SEQ_IN_INDEX = 1 &#8212; report each index only once<br />
UNION ALL<br />
SELECT null<br />
,      CONCAT(PLUGIN_TYPE, &#8216; PLUGIN&#8217;)<br />
,      PLUGIN_NAME<br />
,      PLUGIN_DESCRIPTION<br />
,      null<br />
,      &#8216;library&#8217;<br />
,      PLUGIN_LIBRARY<br />
FROM   information_schema.PLUGINS<br />
UNION ALL<br />
SELECT EVENT_SCHEMA<br />
,      &#8216;EVENT&#8217;<br />
,      EVENT_NAME<br />
,      EVENT_COMMENT<br />
,      EVENT_SCHEMA<br />
,      &#8216;SCHEMA&#8217;<br />
,      EVENT_SCHEMA<br />
FROM   information_schema.EVENTS<br />
UNION ALL<br />
SELECT TRIGGER_SCHEMA<br />
,      CONCAT(ACTION_TIMING, &#8216; &#8216;, EVENT_MANIPULATION, &#8216; &#8216;, ACTION_ORIENTATION, &#8216; TRIGGER&#8217;)<br />
,      TRIGGER_NAME<br />
,      null<br />
,      EVENT_OBJECT_SCHEMA<br />
,      &#8216;BASE TABLE&#8217;<br />
,      EVENT_OBJECT_TABLE<br />
FROM   information_schema.TRIGGERS<br />
UNION ALL<br />
SELECT ROUTINE_SCHEMA<br />
,      ROUTINE_TYPE<br />
,      ROUTINE_NAME<br />
,      ROUTINE_COMMENT<br />
,      ROUTINE_SCHEMA<br />
,      &#8216;SCHEMA&#8217;<br />
,      ROUTINE_SCHEMA<br />
FROM   information_schema.ROUTINES</p>
<p>Caveats:</p>
<p>1) indexes and constraints are reported as separate objects &#8211; in MySQL there is physically no difference between f.e. a UNIQUE CONSTRAINT and the index that implements it &#8211; this view however reports them as separate objects.</p>
<p>2) this is a view on the information schema &#8211; it can be slow on the first run or when there are many many objects in the information schema</p>
<p>3) I don&#8217;t include columns. It clutters he output and IMO they are not objects in themselves.</p>
<p>4) SUPER_OBJECT_SCHEMA always reports a SCHEMA if possible, even if the super object is itself a schema.</p>
<p>5) I excluded the user-defined functions to avoid a dependency on the mysql database.</p>
<p>kind regards,</p>
<p>Roland BOuman</p>
]]></content:encoded>
	</item>
</channel>
</rss>

