Skip to main content
Code Review

Return to Question

added 1882 characters in body; edited title
Source Link

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...

deleted 46 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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).

Post Reopened by Sᴀᴍ Onᴇᴌᴀ , Stephen Rauch, dfhwze, RoToRa, Mast
tags + redundant question removal
Source Link
dfhwze
  • 14.1k
  • 3
  • 40
  • 101

Is this what you need? Thx!!

Is this what you need? Thx!!

added 6 characters in body
Source Link
Loading
edited tags
Link
Loading
added 27691 characters in body
Source Link
Loading
added 27691 characters in body
Source Link
Loading
added 470 characters in body
Source Link
Loading
Post Closed as "Not suitable for this site" by πάντα ῥεῖ, 200_success, Dan Oberlam, dfhwze, Toby Speight
added 4 characters in body
Source Link
Loading
Source Link
Loading
lang-sql

AltStyle によって変換されたページ (->オリジナル) /