Skip to content

Commit 8c5c55a

Browse files
pukumarepukumare
authored andcommitted
Combined required views into a single file
1 parent d65271e commit 8c5c55a

9 files changed

Lines changed: 222 additions & 247 deletions

File tree

autonomous_cloud_import/README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This repository contains prerequisite SQL objects (views) to support **optimal parallel processing** and **reliable restart capability** when migrating from **non-Oracle (heterogeneous) source databases**.
44

5-
You can place the SQL statements provided below into separate files (recommended structure included).
6-
75
---
86

97
## Overview
@@ -30,19 +28,14 @@ If the required views are **not** created on the source database, the migration
3028
### Purpose
3129
To enable parallel processing and reliable restart capability on a PostgreSQL source database, create the required views.
3230

33-
### Files (recommended)
34-
Place the SQL into files such as:
35-
36-
- `postgres/ALL_TAB_PARTITIONS.sql`
37-
- `postgres/ALL_PART_KEY_COLUMNS.sql`
38-
- `postgres/ALL_PART_TABLES.sql`
31+
### Files
32+
- `postgres/views.sql`
3933

4034
### Required Views
4135
- `ALL_TAB_PARTITIONS`
4236
- `ALL_PART_KEY_COLUMNS`
4337
- `ALL_PART_TABLES`
4438

45-
> Add the PostgreSQL SQL definitions to the files above.
4639

4740
---
4841

@@ -56,12 +49,8 @@ Place the SQL into files such as:
5649
### Purpose
5750
To enable parallel processing and reliable restart capability on a MySQL source database, create the required views.
5851

59-
### Files (recommended)
60-
Place the SQL into files such as:
61-
62-
- `mysql/ALL_PART_TABLES.sql`
63-
- `mysql/ALL_PART_KEY_COLUMNS.sql`
64-
- `mysql/ALL_TAB_PARTITIONS.sql`
52+
### Files
53+
- `mysql/views.sql`
6554

6655
### Required Views
6756
- `ALL_PART_TABLES`

autonomous_cloud_import/mysql/ALL_PART_KEY_COLUMNS.sql

Lines changed: 0 additions & 50 deletions
This file was deleted.

autonomous_cloud_import/mysql/ALL_PART_TABLES.sql

Lines changed: 0 additions & 14 deletions
This file was deleted.

autonomous_cloud_import/mysql/ALL_TAB_PARTITIONS.sql

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
-- MySQL view creation script.
2+
-- Execute with: mysql < views.sql
3+
4+
CREATE OR REPLACE VIEW ALL_PART_KEY_COLUMNS AS
5+
WITH part_tables AS (
6+
SELECT DISTINCT
7+
TABLE_SCHEMA,
8+
TABLE_NAME,
9+
PARTITION_EXPRESSION
10+
FROM information_schema.PARTITIONS
11+
WHERE PARTITION_NAME IS NOT NULL
12+
AND PARTITION_EXPRESSION IS NOT NULL
13+
),
14+
key_list AS (
15+
SELECT
16+
TABLE_SCHEMA AS OWNER,
17+
TABLE_NAME AS NAME,
18+
TRIM(
19+
BOTH ')'
20+
FROM TRIM(
21+
BOTH '('
22+
FROM SUBSTRING_INDEX(PARTITION_EXPRESSION, '(', -1)
23+
)
24+
) AS key_list
25+
FROM part_tables
26+
)
27+
SELECT
28+
k.OWNER,
29+
k.NAME,
30+
'TABLE' AS OBJECT_TYPE,
31+
TRIM(BOTH '`' FROM
32+
SUBSTRING_INDEX(
33+
SUBSTRING_INDEX(k.key_list, ',', n.n),
34+
',', -1
35+
)
36+
) AS COLUMN_NAME,
37+
n.n AS COLUMN_POSITION
38+
FROM key_list k
39+
JOIN (
40+
SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL
41+
SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL
42+
SELECT 7 UNION ALL SELECT 8
43+
) n
44+
ON n.n <= 1 + LENGTH(k.key_list) - LENGTH(REPLACE(k.key_list, ',', ''))
45+
WHERE k.key_list NOT REGEXP '[()]'
46+
ORDER BY
47+
k.OWNER,
48+
k.NAME,
49+
COLUMN_POSITION;
50+
51+
CREATE OR REPLACE VIEW ALL_PART_TABLES AS
52+
SELECT
53+
TABLE_SCHEMA AS OWNER,
54+
TABLE_NAME,
55+
PARTITION_METHOD AS PARTITIONING_TYPE,
56+
COUNT(DISTINCT PARTITION_NAME) AS PARTITION_COUNT,
57+
LENGTH(PARTITION_EXPRESSION) - LENGTH(REPLACE(PARTITION_EXPRESSION, ',', '')) + 1 AS PARTITIONING_KEY_COUNT
58+
FROM information_schema.partitions
59+
GROUP BY
60+
TABLE_SCHEMA,
61+
TABLE_NAME,
62+
PARTITION_METHOD,
63+
PARTITION_EXPRESSION;
64+
65+
CREATE OR REPLACE VIEW ALL_TAB_PARTITIONS AS
66+
SELECT
67+
TABLE_SCHEMA AS TABLE_OWNER,
68+
TABLE_NAME,
69+
PARTITION_NAME,
70+
MIN(PARTITION_ORDINAL_POSITION) AS PARTITION_POSITION,
71+
CASE
72+
WHEN MAX(PARTITION_DESCRIPTION) = 'MAXVALUE'
73+
THEN 'MAXVALUE'
74+
ELSE TRIM(BOTH '''' FROM MAX(PARTITION_DESCRIPTION))
75+
END AS HIGH_VALUE,
76+
LENGTH(
77+
CASE
78+
WHEN MAX(PARTITION_DESCRIPTION) = 'MAXVALUE'
79+
THEN 'MAXVALUE'
80+
ELSE TRIM(BOTH '''' FROM MAX(PARTITION_DESCRIPTION))
81+
END
82+
) AS HIGH_VALUE_LENGTH,
83+
MAX(PARTITION_METHOD) AS PARTITIONING_TYPE,
84+
1 AS PARTITION_KEY_COUNT
85+
FROM information_schema.PARTITIONS
86+
WHERE PARTITION_NAME IS NOT NULL
87+
GROUP BY
88+
TABLE_SCHEMA,
89+
TABLE_NAME,
90+
PARTITION_NAME;

autonomous_cloud_import/postgres/ALL_PART_KEY_COLUMNS.sql

Lines changed: 0 additions & 27 deletions
This file was deleted.

autonomous_cloud_import/postgres/ALL_PART_TABLES.sql

Lines changed: 0 additions & 47 deletions
This file was deleted.

autonomous_cloud_import/postgres/ALL_TAB_PARTITIONS.sql

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)