Skip to content

Commit f34415a

Browse files
authored
[b/352468287] Add non-CDB versions of both db-objects SQLs (GoogleCloudPlatform#486)
- add db-objects for non-cdb - add db-objects-synonym-public for non-cdb
1 parent 3d244f4 commit f34415a

3 files changed

Lines changed: 107 additions & 6 deletions

File tree

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/oracle/StatsTaskListGenerator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@ class StatsTaskListGenerator {
5353

5454
private static final ImmutableList<String> NATIVE_NAMES_REQUIRED =
5555
ImmutableList.of(
56-
"data-types",
57-
"db-info",
5856
"db-objects",
5957
// The version of db-objects that gets SYNONYM objects, for which owner is PUBLIC.
6058
// A JOIN is performed to exclude objects which appear in the cdb_synonyms table.
61-
"db-objects-synonym-public",
62-
"table-types-dtl",
63-
"used-space-details");
59+
"db-objects-synonym-public");
60+
61+
private static final ImmutableList<String> NATIVE_NAMES_REQUIRED_CDB_ONLY =
62+
ImmutableList.of("data-types", "db-info", "table-types-dtl", "used-space-details");
6463

6564
private static final ImmutableList<String> STATSPACK_NAMES =
6665
ImmutableList.of("hist-cmd-types-statspack", "sql-stats-statspack");
@@ -93,6 +92,9 @@ ImmutableList<Task<?>> createTasks(ConnectorArguments arguments, Duration querie
9392
for (String name : NATIVE_NAMES_OPTIONAL) {
9493
builder.addAll(createTaskWithAlternative(name, /* isRequired= */ false, queriedDuration));
9594
}
95+
for (String name : NATIVE_NAMES_REQUIRED) {
96+
builder.addAll(createTaskWithAlternative(name, /* isRequired= */ true, queriedDuration));
97+
}
9698
return builder.build();
9799
}
98100

@@ -125,7 +127,7 @@ ImmutableList<String> awrNames() {
125127
}
126128

127129
ImmutableList<String> nativeNames(boolean required) {
128-
return required ? NATIVE_NAMES_REQUIRED : NATIVE_NAMES_OPTIONAL_CDB_ONLY;
130+
return required ? NATIVE_NAMES_REQUIRED_CDB_ONLY : NATIVE_NAMES_OPTIONAL_CDB_ONLY;
129131
}
130132

131133
ImmutableList<String> statspackNames() {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- Copyright 2022-2024 Google LLC
2+
-- Copyright 2013-2021 CompilerWorks
3+
--
4+
-- Licensed under the Apache License, Version 2.0 (the "License");
5+
-- you may not use this file except in compliance with the License.
6+
-- You may obtain a copy of the License at
7+
--
8+
-- http://www.apache.org/licenses/LICENSE-2.0
9+
--
10+
-- Unless required by applicable law or agreed to in writing, software
11+
-- distributed under the License is distributed on an "AS IS" BASIS,
12+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
-- See the License for the specific language governing permissions and
14+
-- limitations under the License.
15+
SELECT
16+
NULL "ConId",
17+
'PUBLIC' "Owner",
18+
'SYNONYM' "ObjectType",
19+
B.editionable "Editionable",
20+
B.object_name "ObjectName",
21+
-- This looks similar to filtering with WHERE and using count() instead of sum().
22+
--
23+
-- It is not similar. DB will see the LIKE inside a WHERE predicate and decide to
24+
-- replace a HASH JOIN with NESTED LOOPS. The JOIN arguments have >10k rows each,
25+
-- so performance-wise the nested loop would be terrible.
26+
sum(
27+
CASE WHEN B.object_name LIKE '/%' THEN 0
28+
WHEN B.object_name LIKE 'BIN$%' THEN 0
29+
ELSE 1 END
30+
) "Count"
31+
FROM (
32+
SELECT
33+
A.editionable,
34+
A.object_name,
35+
A.owner
36+
FROM dba_objects A
37+
WHERE A.object_type = 'SYNONYM'
38+
AND A.owner = 'PUBLIC'
39+
) B
40+
LEFT JOIN (
41+
SELECT
42+
C.synonym_name,
43+
C.table_owner
44+
FROM dba_synonyms C
45+
WHERE C.owner = 'PUBLIC'
46+
AND C.table_owner IS NOT NULL
47+
) D ON B.object_name = D.synonym_name
48+
WHERE D.table_owner IS NULL
49+
AND B.owner = 'PUBLIC'
50+
GROUP BY
51+
B.editionable,
52+
B.object_name
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- Copyright 2022-2024 Google LLC
2+
-- Copyright 2013-2021 CompilerWorks
3+
--
4+
-- Licensed under the Apache License, Version 2.0 (the "License");
5+
-- you may not use this file except in compliance with the License.
6+
-- You may obtain a copy of the License at
7+
--
8+
-- http://www.apache.org/licenses/LICENSE-2.0
9+
--
10+
-- Unless required by applicable law or agreed to in writing, software
11+
-- distributed under the License is distributed on an "AS IS" BASIS,
12+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
-- See the License for the specific language governing permissions and
14+
-- limitations under the License.
15+
SELECT
16+
NULL "ConId",
17+
A.owner "Owner",
18+
A.object_name "ObjectName",
19+
A.object_type "ObjectType",
20+
A.editionable "Editionable",
21+
count(1) "Count"
22+
FROM dba_objects A
23+
WHERE A.owner NOT LIKE '%SYS'
24+
AND A.object_name NOT LIKE 'BIN$%'
25+
AND (A.object_type <> 'SYNONYM' OR A.owner <> 'PUBLIC')
26+
GROUP BY
27+
A.owner,
28+
A.object_name,
29+
A.object_type,
30+
A.editionable
31+
UNION ALL
32+
SELECT
33+
NULL "ConId",
34+
'SYS' "Owner",
35+
B.object_name "ObjectName",
36+
'DIRECTORY' "ObjectType",
37+
B.editionable "Editionable",
38+
count(1) "Count"
39+
FROM dba_objects B
40+
WHERE B.owner = 'SYS'
41+
AND B.object_type = 'DIRECTORY'
42+
AND B.object_name NOT LIKE 'BIN$%'
43+
GROUP BY
44+
B.owner,
45+
B.object_name,
46+
B.object_type,
47+
B.editionable

0 commit comments

Comments
 (0)