r.ObjType is not available to me. Probably an op sys/TR thing.
Original Message:
Sent: Fri April 07, 2023 09:17 PM
From: Robert Cozzi
Subject: find tables and all related objects (even in other libraries) and delete them
Would including the object type in the second lateral help reduce the resultset?
select * from table( qSys2.OBJECT_STATISTICS(OBJECT_SCHEMA => r.library_name, object_name => r.system_name, OBJTYPELIST => R.OBJTYPE))) s2
------------------------------
Robert Cozzi
Original Message:
Sent: Mon February 27, 2023 08:53 AM
From: Patrick Conner
Subject: find tables and all related objects (even in other libraries) and delete them
I ran into a problem. I'm trying to run:
select s.*
from table( qSys2.OBJECT_STATISTICS(OBJECT_SCHEMA => 'SQAATYPE9', OBJTYPELIST => 'ALL')) s
union
select s2.*
from table( qSys2.OBJECT_STATISTICS(OBJECT_SCHEMA => 'SQAATYPE9', OBJTYPELIST => 'ALL')) s,
lateral (select * from table( sysTools.RELATED_OBJECTS(LIBRARY_NAME => s.objLib, FILE_NAME => s.objName))) r,
lateral ( select * from table( qSys2.OBJECT_STATISTICS(OBJECT_SCHEMA => r.library_name, object_name => r.system_name, OBJTYPELIST => 'ALL'))) s2
but I get error:
SQL State: 57005
Vendor Code: -666
Message: [SQL0666] SQL query exceeds specified limit or threshold. Cause . . . . . : A database query was ended by query monitoring tool 1. The tools are: 1 -- Predictive Query Governor
I'm using ACS Run SQL Scripts by the way.
When I break the two queries apart they run fine.
The first query retrieves 97 rows and runs in milliseconds.
select s.* from table( qSys2.OBJECT_STATISTICS(OBJECT_SCHEMA => 'SQAATYPE9', OBJTYPELIST => 'ALL')) s
Statement ran successfully (180 ms)
The second query initially retrieves 100 rows, but when I pagedown it stops at 126
select s2.* from table( qSys2.OBJECT_STATISTICS(OBJECT_SCHEMA => 'SQAATYPE9', OBJTYPELIST => 'ALL')) s, lateral (select * from table( sysTools.RELATED_OBJECTS(LIBRARY_NAME => s.objLib, FILE_NAME => s.objName))) r, lateral ( select * from table( qSys2.OBJECT_STATISTICS(OBJECT_SCHEMA => r.library_name, object_name => r.system_name, OBJTYPELIST => 'ALL'))) s2
Statement ran successfully (1,330 ms = 1.330 sec)
The Predictive Query Governor is guessing 927 seconds of run time which exceeds 300. Seems like the guess is a little excessive. Anything I can do to influence the guess?
Predictive Query Governor: A database query was about to be started whose estimated run time of 927 exceeds the specified limit of 300 or whose estimated temporary storage usage of 28 exceeds the specified limit of 2147352576.
------------------------------
Patrick Conner
Original Message:
Sent: Fri February 24, 2023 03:28 PM
From: Patrick Conner
Subject: find tables and all related objects (even in other libraries) and delete them
We have a library (AALib) that is based on a third party connection. We're moving all objects from that library to our standard production library (ProdLib). Some objects in AALib, like tables for instance, have related objects in other libraries. I need to write a query that reports all objects in AALib and all related objects. Second requirement is to delete all objects and recreate them in our standard change management system. I think this an opportunity to use qCmdExc as a scalar function. Seems like I saw an example that achieves my goal about a year ago; maybe a Scott Forstie video or something. Does anyone have an example or can point me to the example I think I saw?
Thank you. I'm just looking for a jumpstart.
------------------------------
Patrick Conner
------------------------------
#SQL