Problem

One QC process need to obtain tables and their row counts in a database in Netezza. We use the below SQL query to do so:

SELECT CAST(TRIM(RELNAME) AS VARCHAR(50)) TABLE_NAME,

CAST(CASE WHEN RELTUPLES < 0 THEN ((2^32) * RELREFS) + ((2^32) + RELTUPLES ) ELSE ((2^32) * RELREFS) + ( RELTUPLES ) END AS BIGINT) NUM_ROWS

FROM _T_CLASS ,_T_OBJECT 

WHERE _T_OBJECT.OBJID =_T_CLASS.OID AND _T_OBJECT.OBJCLASS = 4905; 

Now oneday an issue occurs, we add a column to one table, but this query output will not include the altered table.

Solution

This issue pushes us to look into the query and the system tables. After making research, the more internally principle of Netezza is gradually discovered.

In Netezza database system, it will use ids(a number) to represent objects(tables, views, stored procedures...) internally. For tables, it will use id 4905 to represent.

   SELECT * FROM _T_OBJECT WHERE OBJCLASS = 4905; 

When a table structure is modified, for example, add/modify/delete a column, the Netezza system will internally use a different  id for the altered table, which is 4961, and the table is called versioned table now.

We could use system view to check whether there is versioned tables in the database:

SELECT * FROM _V_SYS_TABLE_VERSION_OBJECT_DEFN;

And Here is some explanation of versioned table:

Versioned tables come about as a result of doing an alter table. This results in multiple data stores for the table. When you go to query the table, Netezza must recombine the separate data stores back into a single entity. This action will be performed automatically and on-the-fly. But it does result in additional performance cost for using the UNION ALL view instead of having all of the data exist in a single table.Therefore, it is a best practice to reconstitute the table by using:

 GROOM TABLE <tablename> VERSIONS;

And after the groom sql is executed, the id is set back to 4905 for the table.

So as a result of versioned table, it's better to modify the where statement in QC script to:

WHERE _T_OBJECT.OBJID =_T_CLASS.OID AND _T_OBJECT.OBJCLASS IN (4905,4961)

In this way, the query will give expected result even if there is altered table. But again it is suggested to apply the groom clause reasonably soon after table is altered.

(EnD)

Related articles

http://netezza-dba.blogspot.com/2014/06/netezza-versioned-tables.html

最新文章

  1. C# 关于委托和事件的妙文:通过一个例子详细介绍委托和事件的作用;Observer模式简介
  2. JQuery中的html(),text(),val()区别
  3. Redis 环境搭建与使用(C#)
  4. 调用CXF工具 生成 WSDL【转】
  5. Hadoop-Drill深度剖析
  6. js拆分数组
  7. C++ 基本数据结构整理
  8. Effective Java设定游戏 - 就是爱Java
  9. hdu 3681 Prison Break(状态压缩+bfs)
  10. 【POJ】2318 TOYS ——计算几何+二分
  11. Servlet简介及使用
  12. C++的socket编程学习
  13. 读书学习-Python--描述符(python3)
  14. C# 操作Word目录——生成、删除目录
  15. 说一说MVC的CSRF(三)
  16. QTP 自动化测试--点滴 获取datatable数值/dafault文件位置
  17. 第一个用IDEA写的程序——“前言中不允许有内容”
  18. 【读书笔记】iOS-“一心多用”利用多线程提升性能
  19. localhost与127.0.0.1及本机ip的区别
  20. 题目要求:将a,b两个数的值进行交换,并且不使用任何的中间变量。

热门文章

  1. 【HOW】如何配置SharePoint传入/传出电子邮件设置
  2. OpenCV的数据类型---Cv
  3. samba服务器搭建小记
  4. Bay Trail平板安装Ubuntu ThinkPad 8(20BNA00RCD)
  5. gulp和grunt的区别
  6. 《Linux企业应用案例精解(第2版)》新书发售啦
  7. shell 判断文件是否存在
  8. appstore不能登陆
  9. 23. Can&#39;t connect to X11 window server using &#39;127.0.0.1:0.0&#39; as the value of the DISPLAY variable.解决办法
  10. Unity已经学会的