oddgen / bitemp

Code generator to switch between non-temporal, uni-temporal and bi-temporal models while preserving data.
Apache License 2.0
4 stars 1 forks source link

Querying table node is very slow #11

Closed PhilippSalvisberg closed 7 years ago

PhilippSalvisberg commented 7 years ago

Querying the table node takes the first time around 30 seconds. GUI is blocked during the time.

The reason is most probably the named query hist_tabs following query (based on SQL Developer statement history):

WITH 
  tabs AS (
     SELECT /*+ materialize */ object_name AS table_name
       FROM user_objects
      WHERE object_type = 'TABLE'
        AND generated = 'N'
   ),
   hist_tabs AS (
      SELECT /*+ materialize */ table_name
        FROM user_tab_cols
       WHERE column_name = 'VT$'
         AND hidden_column = 'YES'
   ),
   pk_tabs AS (
      SELECT /*+ materialize */ table_name 
        FROM all_constraints
        WHERE constraint_type = 'P' AND owner = USER
   )
SELECT /*+ordered use_hash(tabs) use_hash(hist_tabs) use_has(pk_tabs) */ tabs.table_name
  FROM tabs
  JOIN pk_tabs ON pk_tabs.table_name = tabs.table_name 
  LEFT JOIN hist_tabs ON hist_tabs.table_name = tabs.table_name
 WHERE hist_tabs.table_name is NULL
 ORDER BY tabs.table_name
PhilippSalvisberg commented 7 years ago

This should be better:

WITH 
  tabs AS (
     SELECT /*+ materialize */ object_name AS table_name
       FROM user_objects
      WHERE object_type = 'TABLE'
        AND generated = 'N'
   ),
   cols AS (
      SELECT /*+ materialize */ table_name, column_name, hidden_column
        FROM user_tab_cols
   ),
   hist_tabs AS (
      SELECT DISTINCT table_name
        FROM cols
       WHERE column_name = 'VT$'
         AND hidden_column = 'YES'
   ),
   pk_tabs AS (
      SELECT /*+ materialize */ table_name 
        FROM all_constraints
        WHERE constraint_type = 'P' AND owner = USER
   )
SELECT /*+ordered use_hash(tabs) use_hash(hist_tabs) use_hash(pk_tabs) */ tabs.table_name
  FROM tabs
  JOIN pk_tabs ON pk_tabs.table_name = tabs.table_name 
  LEFT JOIN hist_tabs ON hist_tabs.table_name = tabs.table_name
 WHERE hist_tabs.table_name is NULL
 ORDER BY tabs.table_name