<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>An Ingres Blog &#187; sql</title>
	<atom:link href="http://blogs.planetingres.org/grant/category/sql/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.planetingres.org/grant</link>
	<description>(Other blogs about Ingres are available...)</description>
	<lastBuildDate>Wed, 12 Jan 2011 11:59:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>What BLOB tables do I have?</title>
		<link>http://blogs.planetingres.org/grant/236-what-blob-tables-do-i-have</link>
		<comments>http://blogs.planetingres.org/grant/236-what-blob-tables-do-i-have#comments</comments>
		<pubDate>Tue, 23 Feb 2010 12:39:22 +0000</pubDate>
		<dc:creator>Grant Croker</dc:creator>
				<category><![CDATA[ingres]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[table]]></category>
		<guid isPermaLink="false">http://blogs.planetingres.org/grant/?p=236</guid>
		<description><![CDATA[The following is SQL code was published in the #ingres IRC channel on freenode in response to a question about the best method to determine which iietab_xx_yy table belongs to which table: Running this against my demodb database I get the following: ┌────────────────────────────────┬────────────────────────────────┬────────────────────────────────┐ │base_table │column_name │extend_table │ ├────────────────────────────────┼────────────────────────────────┼────────────────────────────────┤ │nclob │ntext │iietab_367_368 │ │nclob2 │ntext │iietab_369_36a [...]]]></description>
			<content:encoded><![CDATA[<p>The following is SQL code was published in the <a href="http://community.ingres.com/wiki/IRC">#ingres</a> IRC channel on freenode in response to a <a href="http://irc.planetingres.org/%23ingres.2010-02-18.log.html#t2010-02-18T01:58:08">question</a> about the best method to determine which <em>iietab_xx_yy</em> table belongs to which table:</p>
<pre class="brush: sql; title: ; notranslate">
select r1.relid as base_table,
       c.attname as column_name,
       r2.relid as extend_table
from iirelation r1,iirelation r2,iiattribute c,iiextended_relation e
where r1.reltid=e.etab_base and r2.reltid=e.etab_extension
  and r1.reltid=c.attrelid
  and c.attid=e.etab_attid
  and r1.reltidx=0
  and c.attrelidx=0
order by base_table,column_name
</pre>
<p>Running this against my <em>demodb</em> database I get the following:</p>
<pre>┌────────────────────────────────┬────────────────────────────────┬────────────────────────────────┐
│base_table                      │column_name                     │extend_table                    │
├────────────────────────────────┼────────────────────────────────┼────────────────────────────────┤
│nclob                           │ntext                           │iietab_367_368                  │
│nclob2                          │ntext                           │iietab_369_36a                  │
│nclob2                          │ntext2                          │iietab_369_36b                  │
│nclob3                          │ntext                           │iietab_3c0_3c1                  │
│user_profile                    │up_image                        │iietab_f5_f6                    │
└────────────────────────────────┴────────────────────────────────┴────────────────────────────────┘
(5 rows)
</pre>
<p>Extending the above query we can also determine the size of each <em>iietab_xx_yy</em> table:</p>
<pre class="brush: sql; title: ; notranslate">
select r1.relid as base_table,
       c.attname as column_name,
       r2.relid as extend_table,
	   t.allocated_pages * float4(t.table_pagesize) / 1024 / 1024
       as megabytes
from iirelation r1, iirelation r2,
     iiattribute c, iiextended_relation e,
     iitables t
where r1.reltid=e.etab_base
  and r2.reltid=e.etab_extension
  and r1.reltid=c.attrelid
  and c.attid=e.etab_attid
  and r1.reltidx=0
  and c.attrelidx=0
  and t.table_reltid = e.etab_extension
  order by megabytes desc;
</pre>
<p>For example:</p>
<pre>┌────────────────────────────────┬────────────────────────────────┬────────────────────────────────┬───────────┐
│base_table                      │column_name                     │extend_table                    │megabytes  │
├────────────────────────────────┼────────────────────────────────┼────────────────────────────────┼───────────┤
│nclob2                          │ntext2                          │iietab_369_36b                  │      1.258│
│nclob2                          │ntext                           │iietab_369_36a                  │      0.258│
│nclob                           │ntext                           │iietab_367_368                  │      0.258│
│nclob3                          │ntext                           │iietab_3c0_3c1                  │      0.258│
│user_profile                    │up_image                        │iietab_f5_f6                    │      0.258│
└────────────────────────────────┴────────────────────────────────┴────────────────────────────────┴───────────┘
</pre>
<p>Useful if you want to know how much space your BLOB/CLOB data is taking up. Thanks to Kristoff, Paul and Gerhard for working out the SQL.</p>
<p><em>Updated to recognize Kristoff Picards&#8217; contribution</em><br />
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://blogs.planetingres.org/grant/365-using-ima-to-get-a-list-of-inboundoutbound-connections-in-gcc" title="Using IMA to get a list of inbound/outbound connections in GCC">Using IMA to get a list of inbound/outbound connections in GCC</a></li>
<li><a href="http://blogs.planetingres.org/grant/88-logging-ingres-jdbc-connections-under-tomcat" title="Logging Ingres JDBC connections under tomcat">Logging Ingres JDBC connections under tomcat</a></li>
<li><a href="http://blogs.planetingres.org/grant/354-ingres-ruby-driver-updated-version-1-4-1" title="Ingres Ruby driver updated &#8211; version 1.4.1">Ingres Ruby driver updated &#8211; version 1.4.1</a></li>
</ul>
<img src="http://blogs.planetingres.org/grant/?ak_action=api_record_view&id=236&type=feed" alt="" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblogs.planetingres.org%2Fgrant%2F236-what-blob-tables-do-i-have&amp;title=What%20BLOB%20tables%20do%20I%20have%3F" id="wpa2a_2"><img src="http://blogs.planetingres.org/grant/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blogs.planetingres.org/grant/236-what-blob-tables-do-i-have/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

