Seek to get acceptable performance of SQL request (SOLVED)
SOLUTION
CREATE GLOBAL TEMPORARY TABLE std_temp_table
(
constraint_name varchar2(45)
)
ON COMMIT PRESERVE ROWS;
-- Insert.
INSERT INTO std_temp_table (constraint_name)
WITH names
AS
(
SELECT 'AB_C_COST_GRP_ID' FROM dual UNION ALL
...
SELECT 'ZN_FR_ID' FROM dual UNION ALL
SELECT 'ZN_SYST_ID' FROM dual
)
SELECT *
FROM names;
SELECT owner, table_name, constraint_name, r_owner, r_constraint_name, status
FROM all_constraints
WHERE constraint_type = 'R' -- "Referential integrity"
AND r_constraint_name IN
(
SELECT constraint_name
FROM all_constraints
WHERE constraint_type IN ('P', 'U') -- "Primary key" or "Unique"
)
AND owner NOT IN ('CTXSYS', 'MDSYS', 'SYS', 'SYSTEM', 'XDB')
AND constraint_name NOT IN (SELECT constraint_name FROM std_temp_table);
takes around 6.5 seconds!!
The other variant, with a JOIN, takes around 7 seconds:
SELECT owner, table_name, ac.constraint_name, std_temp_table.constraint_name, r_owner, r_constraint_name, status
FROM all_constraints ac
FULL OUTER JOIN std_temp_table
ON ac.constraint_name = std_temp_table.constraint_name
WHERE constraint_type = 'R' -- "Referential integrity"
AND r_constraint_name IN
(
SELECT constraint_name
FROM all_constraints
WHERE constraint_type IN ('P', 'U') -- "Primary key" or "Unique"
)
AND owner NOT IN ('CTXSYS', 'MDSYS', 'SYS', 'SYSTEM', 'XDB')
AND std_temp_table.constraint_name IS NULL;
PS- Both must be equivalent, simply not run enough times. So the choice then comes down to a question of readability...
Seek to get acceptable performance of SQL request
Seek to get acceptable performance of SQL request (SOLVED)
SOLUTION
CREATE GLOBAL TEMPORARY TABLE std_temp_table
(
constraint_name varchar2(45)
)
ON COMMIT PRESERVE ROWS;
-- Insert.
INSERT INTO std_temp_table (constraint_name)
WITH names
AS
(
SELECT 'AB_C_COST_GRP_ID' FROM dual UNION ALL
...
SELECT 'ZN_FR_ID' FROM dual UNION ALL
SELECT 'ZN_SYST_ID' FROM dual
)
SELECT *
FROM names;
SELECT owner, table_name, constraint_name, r_owner, r_constraint_name, status
FROM all_constraints
WHERE constraint_type = 'R' -- "Referential integrity"
AND r_constraint_name IN
(
SELECT constraint_name
FROM all_constraints
WHERE constraint_type IN ('P', 'U') -- "Primary key" or "Unique"
)
AND owner NOT IN ('CTXSYS', 'MDSYS', 'SYS', 'SYSTEM', 'XDB')
AND constraint_name NOT IN (SELECT constraint_name FROM std_temp_table);
takes around 6.5 seconds!!
The other variant, with a JOIN, takes around 7 seconds:
SELECT owner, table_name, ac.constraint_name, std_temp_table.constraint_name, r_owner, r_constraint_name, status
FROM all_constraints ac
FULL OUTER JOIN std_temp_table
ON ac.constraint_name = std_temp_table.constraint_name
WHERE constraint_type = 'R' -- "Referential integrity"
AND r_constraint_name IN
(
SELECT constraint_name
FROM all_constraints
WHERE constraint_type IN ('P', 'U') -- "Primary key" or "Unique"
)
AND owner NOT IN ('CTXSYS', 'MDSYS', 'SYS', 'SYSTEM', 'XDB')
AND std_temp_table.constraint_name IS NULL;
PS- Both must be equivalent, simply not run enough times. So the choice then comes down to a question of readability...
Seek to get acceptable performance of SQL request (now takes 6 minutes to complete!)
...... with 2,631 constraints names (= the known FK in our standard DB) which I then exclude from the listing (via the WHERE
clause).
UPDATE -- Answer to pertinent questions...
Seek to get acceptable performance of SQL request (now takes 6 minutes to complete!)
... with 2,631 constraints names (= the known FK in our standard DB) which I then exclude from the listing (via the WHERE
clause).
UPDATE -- Answer to pertinent questions...
Seek to get acceptable performance of SQL request
... with 2,631 constraints names (= the known FK in our standard DB) which I then exclude from the listing (via the WHERE
clause).