@@ -16,6 +16,7 @@ create or replace package body ut_annotation_manager as
1616 limitations under the License.
1717 */
1818
19+ gc_max_objects_limit integer := 1000000;
1920 ------------------------------
2021 --private definitions
2122
@@ -24,29 +25,28 @@ create or replace package body ut_annotation_manager as
2425 l_ut_owner varchar2(250) := ut_utils.ut_owner;
2526 l_objects_view varchar2(200) := ut_metadata.get_objects_view_name();
2627 l_cursor_text varchar2(32767);
28+ l_data ut_annotation_objs_cache_info;
2729 l_result ut_annotation_objs_cache_info;
30+ l_card natural;
2831 begin
32+ l_data := ut_annotation_cache_manager.get_annotations_objects_info(a_object_owner, a_object_type);
33+ l_card := ut_utils.scale_cardinality(cardinality(l_data));
34+
2935 l_cursor_text :=
30- q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
31- object_owner => i.object_owner,
32- object_name => i.object_name,
33- object_type => i.object_type,
34- needs_refresh => null
35- )
36- from ]'||l_ut_owner||q'[.ut_annotation_cache_info i
36+ 'select /*+ cardinality(i '||l_card||') */
37+ value(i)
38+ from table( cast( :l_data as '||l_ut_owner||'.ut_annotation_objs_cache_info ) ) i
3739 where
3840 not exists (
39- select 1 from ] '||l_objects_view||q'[ o
41+ select 1 from '||l_objects_view||q'[ o
4042 where o.owner = i.object_owner
4143 and o.object_name = i.object_name
4244 and o.object_type = i.object_type
43- and o.owner = :a_object_owner
44- and o.object_type = :a_object_type
45- )
46- and i.object_owner = :a_object_owner
47- and i.object_type = :a_object_type]';
48- open l_rows for l_cursor_text using a_object_owner, a_object_type, a_object_owner, a_object_type;
49- fetch l_rows bulk collect into l_result limit 1000000;
45+ and o.owner = ']'||ut_utils.qualified_sql_name(a_object_owner)||q'['
46+ and o.object_type = ']'||ut_utils.qualified_sql_name(a_object_type)||q'['
47+ )]';
48+ open l_rows for l_cursor_text using l_data;
49+ fetch l_rows bulk collect into l_result limit gc_max_objects_limit;
5050 close l_rows;
5151 return l_result;
5252 end;
@@ -61,83 +61,48 @@ create or replace package body ut_annotation_manager as
6161 l_ut_owner varchar2(250) := ut_utils.ut_owner;
6262 l_objects_view varchar2(200) := ut_metadata.get_objects_view_name();
6363 l_cursor_text varchar2(32767);
64+ l_data ut_annotation_objs_cache_info;
6465 l_result ut_annotation_objs_cache_info;
65- l_object_owner varchar2(250);
66- l_object_type varchar2(250);
6766 begin
6867 ut_event_manager.trigger_event(
6968 'get_annotation_objs_info - start ( a_full_scan = ' || ut_utils.to_string(a_full_scan) || ' )'
7069 );
70+
71+ l_data := ut_annotation_cache_manager.get_annotations_objects_info(a_object_owner, a_object_type);
72+
7173 if not a_full_scan then
72- l_cursor_text :=
73- q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
74- object_owner => i.object_owner,
75- object_name => i.object_name,
76- object_type => i.object_type,
77- needs_refresh => 'N'
78- )
79- from ]'||l_ut_owner||q'[.ut_annotation_cache_info i
80- where i.object_owner = :a_object_owner
81- and i.object_type = :a_object_type]';
82- open l_rows for l_cursor_text using a_object_owner, a_object_type;
74+ l_result := l_data;
8375 else
84- if a_object_owner is not null then
85- l_object_owner := sys.dbms_assert.qualified_sql_name(a_object_owner);
86- end if;
87- if a_object_type is not null then
88- l_object_type := sys.dbms_assert.qualified_sql_name(a_object_type);
89- end if;
9076 l_cursor_text :=
91- q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
92- object_owner => o.owner,
93- object_name => o.object_name,
94- object_type => o.object_type,
95- needs_refresh => case when o.last_ddl_time < cast(i.parse_time as date) then 'N' else 'Y' end
96- )
97- from ]'||l_objects_view||q'[ o
98- left join ]'||l_ut_owner||q'[.ut_annotation_cache_info i
77+ 'select /*+ cardinality(i '||ut_utils.scale_cardinality(cardinality(l_data))||') */
78+ '||l_ut_owner||q'[.ut_annotation_obj_cache_info(
79+ object_owner => o.owner,
80+ object_name => o.object_name,
81+ object_type => o.object_type,
82+ needs_refresh => case when o.last_ddl_time < cast(i.parse_time as date) then 'N' else 'Y' end,
83+ parse_time => i.parse_time
84+ )
85+ from ]'||l_objects_view||' o
86+ left join table( cast(:l_data as '||l_ut_owner||q'[.ut_annotation_objs_cache_info ) ) i
9987 on o.owner = i.object_owner
10088 and o.object_name = i.object_name
10189 and o.object_type = i.object_type
102- where o.owner = ']'||l_object_owner ||q'['
103- and o.object_type = ']'||l_object_type ||q'['
90+ where o.owner = ']'||ut_utils.qualified_sql_name(a_object_owner) ||q'['
91+ and o.object_type = ']'||ut_utils.qualified_sql_name(a_object_type) ||q'['
10492 and ]'
10593 || case
10694 when a_parse_date is null
10795 then ':a_parse_date is null'
10896 else 'o.last_ddl_time >= cast(:a_parse_date as date)'
10997 end;
110- open l_rows for l_cursor_text using a_parse_date;
98+ open l_rows for l_cursor_text using l_data, a_parse_date;
99+ fetch l_rows bulk collect into l_result limit gc_max_objects_limit;
100+ close l_rows;
111101 end if;
112- fetch l_rows bulk collect into l_result limit 10000000;
113- close l_rows;
114102 ut_event_manager.trigger_event('get_annotation_objs_info - end (count='||l_result.count||')');
115103 return l_result;
116104 end;
117105
118- function get_sources_to_annotate(a_object_owner varchar2, a_object_type varchar2) return sys_refcursor is
119- l_result sys_refcursor;
120- l_sources_view varchar2(200) := ut_metadata.get_source_view_name();
121- begin
122- open l_result for
123- q'[select s.name, s.text
124- from (select s.name, s.text, s.line,
125- max(case when s.text like '%--%\%%' escape '\'
126- and regexp_like(s.text,'--\s*%')
127- then 'Y' else 'N' end
128- )
129- over(partition by s.name) is_annotated
130- from ]'||l_sources_view||q'[ s
131- where s.type = :a_object_type
132- and s.owner = :a_object_owner
133- ) s
134- where s.is_annotated = 'Y'
135- order by s.name, s.line]'
136- using a_object_type, a_object_owner, a_object_type, a_object_owner;
137-
138- return l_result;
139- end;
140-
141106 function get_sources_to_annotate(a_object_owner varchar2, a_object_type varchar2, a_objects_to_refresh ut_annotation_objs_cache_info) return sys_refcursor is
142107 l_result sys_refcursor;
143108 l_sources_view varchar2(200) := ut_metadata.get_source_view_name();
@@ -158,12 +123,12 @@ create or replace package body ut_annotation_manager as
158123 on s.name = r.object_name
159124 and s.owner = r.object_owner
160125 and s.type = r.object_type
161- where s.type = :a_object_type
162- and s.owner = :a_object_owner
126+ where s.owner = ']'||ut_utils.qualified_sql_name(a_object_owner)||q'['
127+ and s.type = ']'||ut_utils.qualified_sql_name(a_object_type)||q'['
163128 ) s
164129 where s.is_annotated = 'Y'
165130 order by s.name, s.line]'
166- using a_objects_to_refresh, a_object_type, a_object_owner ;
131+ using a_objects_to_refresh;
167132
168133 return l_result;
169134 end;
@@ -257,7 +222,6 @@ create or replace package body ut_annotation_manager as
257222 procedure trigger_obj_annotation_rebuild is
258223 l_sql_text ora_name_list_t;
259224 l_parts binary_integer;
260- l_object_to_parse ut_annotation_obj_cache_info;
261225 l_restricted_users ora_name_list_t;
262226
263227 function get_source_from_sql_text(a_object_name varchar2, a_sql_text ora_name_list_t, a_parts binary_integer) return sys_refcursor is
@@ -312,8 +276,6 @@ create or replace package body ut_annotation_manager as
312276 return;
313277 end if;
314278
315- l_object_to_parse := ut_annotation_obj_cache_info(ora_dict_obj_owner, ora_dict_obj_name, ora_dict_obj_type, 'Y');
316-
317279 if ora_sysevent = 'CREATE' then
318280 l_parts := ORA_SQL_TXT(l_sql_text);
319281 build_annot_cache_for_sources(
@@ -324,9 +286,13 @@ create or replace package body ut_annotation_manager as
324286 build_annot_cache_for_sources(
325287 ora_dict_obj_owner, ora_dict_obj_type,
326288 get_source_for_object(ora_dict_obj_owner, ora_dict_obj_name, ora_dict_obj_type)
327- );
289+ );
328290 elsif ora_sysevent = 'DROP' then
329- ut_annotation_cache_manager.remove_from_cache(ut_annotation_objs_cache_info(l_object_to_parse));
291+ ut_annotation_cache_manager.remove_from_cache(
292+ ut_annotation_objs_cache_info(
293+ ut_annotation_obj_cache_info(ora_dict_obj_owner, ora_dict_obj_name, ora_dict_obj_type, 'Y', null)
294+ )
295+ );
330296 end if;
331297 end if;
332298 end;
0 commit comments