2026-03-12 20:23:15
This commit is contained in:
30
tpt/ppx/avg_order_item_price.sql
Normal file
30
tpt/ppx/avg_order_item_price.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
SELECT /*+ MONITOR NO_PARALLEL */
|
||||
c.customer_id
|
||||
, c.cust_first_name
|
||||
, c.cust_last_name
|
||||
, c.credit_limit
|
||||
, o.order_mode
|
||||
, avg(oi.unit_price)
|
||||
FROM
|
||||
soe.customers c
|
||||
, soe.orders o
|
||||
, soe.order_items oi
|
||||
WHERE
|
||||
-- join
|
||||
c.customer_id = o.customer_id
|
||||
AND o.order_id = oi.order_id
|
||||
-- filter
|
||||
AND o.order_mode = 'direct'
|
||||
GROUP BY
|
||||
c.customer_id
|
||||
, c.cust_first_name
|
||||
, c.cust_last_name
|
||||
, c.credit_limit
|
||||
, o.order_mode
|
||||
HAVING
|
||||
sum(oi.unit_price) > c.credit_limit * 100
|
||||
/
|
||||
|
||||
25
tpt/ppx/part_access_path.sql
Normal file
25
tpt/ppx/part_access_path.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
DROP TABLE t;
|
||||
|
||||
CREATE TABLE t (a int, b varchar2(100))
|
||||
PARTITION BY RANGE (a) (
|
||||
PARTITION p1 VALUES LESS THAN (10)
|
||||
,PARTITION p2 VALUES LESS THAN (20)
|
||||
)
|
||||
/
|
||||
|
||||
INSERT INTO t SELECT 5, 'axxxxxxxxxxxxxxxxx' FROM dual;
|
||||
INSERT INTO t SELECT 5, 'bxxxxxxxxxxxxxxxxx' FROM dual;
|
||||
INSERT INTO t SELECT 5, 'cxxxxxxxxxxxxxxxxx' FROM dual;
|
||||
|
||||
INSERT INTO t SELECT 15, 'axxxxxxxxxxxxxxxxx' FROM dual;
|
||||
INSERT INTO t SELECT 15, 'bxxxxxxxxxxxxxxxxx' FROM dual;
|
||||
INSERT INTO t SELECT 15, 'cxxxxxxxxxxxxxxxxx' FROM dual CONNECT BY LEVEL <= 10000;
|
||||
|
||||
CREATE INDEX i1 ON t(a) LOCAL;
|
||||
CREATE INDEX i2 ON t(b) LOCAL;
|
||||
|
||||
@gts t
|
||||
|
||||
14
tpt/ppx/ppx_setup.sql
Normal file
14
tpt/ppx/ppx_setup.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
DEF ppxuser=SOE
|
||||
DEF oeuser=SOE
|
||||
DEF ppxtablespace=SOE
|
||||
|
||||
PROMPT Creating 3 partitioned tables in &ppxuser schema...
|
||||
|
||||
-- Create clone tables
|
||||
@range_part
|
||||
@range_hash_subpart
|
||||
@range_id_part
|
||||
|
||||
55
tpt/ppx/range_hash_subpart.sql
Normal file
55
tpt/ppx/range_hash_subpart.sql
Normal file
@@ -0,0 +1,55 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
CREATE TABLE &ppxuser..orders_range_hash (
|
||||
order_id NUMBER(12) NOT NULL
|
||||
, order_date TIMESTAMP(6) NOT NULL
|
||||
, order_mode VARCHAR2(8)
|
||||
, customer_id NUMBER(12) NOT NULL
|
||||
, order_status NUMBER(2)
|
||||
, order_total NUMBER(8,2)
|
||||
, sales_rep_id NUMBER(6)
|
||||
, promotion_id NUMBER(6)
|
||||
, warehouse_id NUMBER(6)
|
||||
, delivery_type VARCHAR2(15)
|
||||
, cost_of_delivery NUMBER(6)
|
||||
, wait_till_all_available VARCHAR2(15)
|
||||
, delivery_address_id NUMBER(12)
|
||||
, customer_class VARCHAR2(30)
|
||||
, card_id NUMBER(12)
|
||||
, invoice_address_id NUMBER(12)
|
||||
)
|
||||
PARTITION BY RANGE (order_date)
|
||||
SUBPARTITION BY HASH (customer_id)
|
||||
SUBPARTITION TEMPLATE(
|
||||
SUBPARTITION sp1 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp2 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp3 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp4 TABLESPACE &ppxtablespace)
|
||||
(
|
||||
PARTITION Y2007_07 VALUES LESS THAN (DATE'2007-08-01')
|
||||
, PARTITION Y2007_08 VALUES LESS THAN (DATE'2007-09-01')
|
||||
, PARTITION Y2007_09 VALUES LESS THAN (DATE'2007-10-01')
|
||||
, PARTITION Y2007_10 VALUES LESS THAN (DATE'2007-11-01')
|
||||
, PARTITION Y2007_11 VALUES LESS THAN (DATE'2007-12-01')
|
||||
, PARTITION Y2007_12 VALUES LESS THAN (DATE'2008-01-01')
|
||||
, PARTITION Y2008_01 VALUES LESS THAN (DATE'2008-02-01')
|
||||
, PARTITION Y2008_02 VALUES LESS THAN (DATE'2008-03-01')
|
||||
, PARTITION Y2008_03 VALUES LESS THAN (DATE'2008-04-01')
|
||||
, PARTITION Y2008_04 VALUES LESS THAN (DATE'2008-05-01')
|
||||
, PARTITION Y2008_05 VALUES LESS THAN (DATE'2008-06-01')
|
||||
, PARTITION Y2008_06 VALUES LESS THAN (DATE'2008-07-01')
|
||||
, PARTITION Y2008_07 VALUES LESS THAN (DATE'2008-08-01')
|
||||
, PARTITION Y2008_08 VALUES LESS THAN (MAXVALUE)
|
||||
)
|
||||
COMPRESS
|
||||
/
|
||||
|
||||
INSERT /*+ APPEND */ INTO &ppxuser..orders_range_hash
|
||||
SELECT * FROM &oeuser..orders
|
||||
/
|
||||
|
||||
COMMIT;
|
||||
|
||||
EXEC DBMS_STATS.GATHER_TABLE_STATS('&ppxuser', 'ORDERS_RANGE_HASH');
|
||||
|
||||
67
tpt/ppx/range_hash_subpart_16.sql
Normal file
67
tpt/ppx/range_hash_subpart_16.sql
Normal file
@@ -0,0 +1,67 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
CREATE TABLE &ppxuser..orders_range_hash_16 (
|
||||
order_id NUMBER(12) NOT NULL
|
||||
, order_date TIMESTAMP(6) NOT NULL
|
||||
, order_mode VARCHAR2(8)
|
||||
, customer_id NUMBER(12) NOT NULL
|
||||
, order_status NUMBER(2)
|
||||
, order_total NUMBER(8,2)
|
||||
, sales_rep_id NUMBER(6)
|
||||
, promotion_id NUMBER(6)
|
||||
, warehouse_id NUMBER(6)
|
||||
, delivery_type VARCHAR2(15)
|
||||
, cost_of_delivery NUMBER(6)
|
||||
, wait_till_all_available VARCHAR2(15)
|
||||
, delivery_address_id NUMBER(12)
|
||||
, customer_class VARCHAR2(30)
|
||||
, card_id NUMBER(12)
|
||||
, invoice_address_id NUMBER(12)
|
||||
)
|
||||
PARTITION BY RANGE (order_date)
|
||||
SUBPARTITION BY HASH (customer_id)
|
||||
SUBPARTITION TEMPLATE(
|
||||
SUBPARTITION sp01 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp02 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp03 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp04 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp05 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp06 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp07 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp08 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp09 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp10 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp11 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp12 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp13 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp14 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp15 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp16 TABLESPACE &ppxtablespace)
|
||||
(
|
||||
PARTITION Y2007_07 VALUES LESS THAN (DATE'2007-08-01')
|
||||
, PARTITION Y2007_08 VALUES LESS THAN (DATE'2007-09-01')
|
||||
, PARTITION Y2007_09 VALUES LESS THAN (DATE'2007-10-01')
|
||||
, PARTITION Y2007_10 VALUES LESS THAN (DATE'2007-11-01')
|
||||
, PARTITION Y2007_11 VALUES LESS THAN (DATE'2007-12-01')
|
||||
, PARTITION Y2007_12 VALUES LESS THAN (DATE'2008-01-01')
|
||||
, PARTITION Y2008_01 VALUES LESS THAN (DATE'2008-02-01')
|
||||
, PARTITION Y2008_02 VALUES LESS THAN (DATE'2008-03-01')
|
||||
, PARTITION Y2008_03 VALUES LESS THAN (DATE'2008-04-01')
|
||||
, PARTITION Y2008_04 VALUES LESS THAN (DATE'2008-05-01')
|
||||
, PARTITION Y2008_05 VALUES LESS THAN (DATE'2008-06-01')
|
||||
, PARTITION Y2008_06 VALUES LESS THAN (DATE'2008-07-01')
|
||||
, PARTITION Y2008_07 VALUES LESS THAN (DATE'2008-08-01')
|
||||
, PARTITION Y2008_08 VALUES LESS THAN (MAXVALUE)
|
||||
)
|
||||
COMPRESS
|
||||
/
|
||||
|
||||
INSERT /*+ APPEND */ INTO &ppxuser..orders_range_hash_16
|
||||
SELECT * FROM &oeuser..orders_range_hash
|
||||
/
|
||||
|
||||
COMMIT;
|
||||
|
||||
EXEC DBMS_STATS.GATHER_TABLE_STATS('&ppxuser', 'ORDERS_RANGE_HASH_16');
|
||||
|
||||
68
tpt/ppx/range_hash_subpart_17.sql
Normal file
68
tpt/ppx/range_hash_subpart_17.sql
Normal file
@@ -0,0 +1,68 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
CREATE TABLE &ppxuser..orders_range_hash_17 (
|
||||
order_id NUMBER(12) NOT NULL
|
||||
, order_date TIMESTAMP(6) NOT NULL
|
||||
, order_mode VARCHAR2(8)
|
||||
, customer_id NUMBER(12) NOT NULL
|
||||
, order_status NUMBER(2)
|
||||
, order_total NUMBER(8,2)
|
||||
, sales_rep_id NUMBER(6)
|
||||
, promotion_id NUMBER(6)
|
||||
, warehouse_id NUMBER(6)
|
||||
, delivery_type VARCHAR2(15)
|
||||
, cost_of_delivery NUMBER(6)
|
||||
, wait_till_all_available VARCHAR2(15)
|
||||
, delivery_address_id NUMBER(12)
|
||||
, customer_class VARCHAR2(30)
|
||||
, card_id NUMBER(12)
|
||||
, invoice_address_id NUMBER(12)
|
||||
)
|
||||
PARTITION BY RANGE (order_date)
|
||||
SUBPARTITION BY HASH (customer_id)
|
||||
SUBPARTITION TEMPLATE(
|
||||
SUBPARTITION sp01 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp02 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp03 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp04 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp05 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp06 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp07 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp08 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp09 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp10 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp11 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp12 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp13 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp14 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp15 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp16 TABLESPACE &ppxtablespace,
|
||||
SUBPARTITION sp17 TABLESPACE &ppxtablespace)
|
||||
(
|
||||
PARTITION Y2007_07 VALUES LESS THAN (DATE'2007-08-01')
|
||||
, PARTITION Y2007_08 VALUES LESS THAN (DATE'2007-09-01')
|
||||
, PARTITION Y2007_09 VALUES LESS THAN (DATE'2007-10-01')
|
||||
, PARTITION Y2007_10 VALUES LESS THAN (DATE'2007-11-01')
|
||||
, PARTITION Y2007_11 VALUES LESS THAN (DATE'2007-12-01')
|
||||
, PARTITION Y2007_12 VALUES LESS THAN (DATE'2008-01-01')
|
||||
, PARTITION Y2008_01 VALUES LESS THAN (DATE'2008-02-01')
|
||||
, PARTITION Y2008_02 VALUES LESS THAN (DATE'2008-03-01')
|
||||
, PARTITION Y2008_03 VALUES LESS THAN (DATE'2008-04-01')
|
||||
, PARTITION Y2008_04 VALUES LESS THAN (DATE'2008-05-01')
|
||||
, PARTITION Y2008_05 VALUES LESS THAN (DATE'2008-06-01')
|
||||
, PARTITION Y2008_06 VALUES LESS THAN (DATE'2008-07-01')
|
||||
, PARTITION Y2008_07 VALUES LESS THAN (DATE'2008-08-01')
|
||||
, PARTITION Y2008_08 VALUES LESS THAN (MAXVALUE)
|
||||
)
|
||||
COMPRESS
|
||||
/
|
||||
|
||||
INSERT /*+ APPEND */ INTO &ppxuser..orders_range_hash_17
|
||||
SELECT * FROM &oeuser..orders_range_hash
|
||||
/
|
||||
|
||||
COMMIT;
|
||||
|
||||
EXEC DBMS_STATS.GATHER_TABLE_STATS('&ppxuser', 'ORDERS_RANGE_HASH_17');
|
||||
|
||||
42
tpt/ppx/range_id_part.sql
Normal file
42
tpt/ppx/range_id_part.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
CREATE TABLE &PPXUSER..orders_id_range (
|
||||
order_id NUMBER(12) NOT NULL
|
||||
, order_date TIMESTAMP(6) NOT NULL
|
||||
, order_mode VARCHAR2(8)
|
||||
, customer_id NUMBER(12) NOT NULL
|
||||
, order_status NUMBER(2)
|
||||
, order_total NUMBER(8,2)
|
||||
, sales_rep_id NUMBER(6)
|
||||
, promotion_id NUMBER(6)
|
||||
, warehouse_id NUMBER(6)
|
||||
, delivery_type VARCHAR2(15)
|
||||
, cost_of_delivery NUMBER(6)
|
||||
, wait_till_all_available VARCHAR2(15)
|
||||
, delivery_address_id NUMBER(12)
|
||||
, customer_class VARCHAR2(30)
|
||||
, card_id NUMBER(12)
|
||||
, invoice_address_id NUMBER(12)
|
||||
)
|
||||
PARTITION BY RANGE (order_id) (
|
||||
PARTITION id_00m VALUES LESS THAN (1000000)
|
||||
, PARTITION id_01m VALUES LESS THAN (2000000)
|
||||
, PARTITION id_02m VALUES LESS THAN (3000000)
|
||||
, PARTITION id_03m VALUES LESS THAN (4000000)
|
||||
, PARTITION id_04m VALUES LESS THAN (5000000)
|
||||
, PARTITION id_05m VALUES LESS THAN (6000000)
|
||||
, PARTITION id_06m VALUES LESS THAN (7000000)
|
||||
, PARTITION id_07m VALUES LESS THAN (8000000)
|
||||
, PARTITION id_08m VALUES LESS THAN (9000000)
|
||||
, PARTITION id_09m VALUES LESS THAN (MAXVALUE)
|
||||
)
|
||||
TABLESPACE &ppxtablespace
|
||||
COMPRESS
|
||||
/
|
||||
|
||||
INSERT /*+ APPEND */ INTO &PPXUSER..orders_id_range SELECT * FROM &OEUSER..orders
|
||||
/
|
||||
|
||||
COMMIT;
|
||||
|
||||
48
tpt/ppx/range_part.sql
Normal file
48
tpt/ppx/range_part.sql
Normal file
@@ -0,0 +1,48 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
CREATE TABLE &ppxuser..orders_range (
|
||||
order_id NUMBER(12) NOT NULL
|
||||
, order_date TIMESTAMP(6) NOT NULL
|
||||
, order_mode VARCHAR2(8)
|
||||
, customer_id NUMBER(12) NOT NULL
|
||||
, order_status NUMBER(2)
|
||||
, order_total NUMBER(8,2)
|
||||
, sales_rep_id NUMBER(6)
|
||||
, promotion_id NUMBER(6)
|
||||
, warehouse_id NUMBER(6)
|
||||
, delivery_type VARCHAR2(15)
|
||||
, cost_of_delivery NUMBER(6)
|
||||
, wait_till_all_available VARCHAR2(15)
|
||||
, delivery_address_id NUMBER(12)
|
||||
, customer_class VARCHAR2(30)
|
||||
, card_id NUMBER(12)
|
||||
, invoice_address_id NUMBER(12)
|
||||
)
|
||||
PARTITION BY RANGE (order_date) (
|
||||
PARTITION Y2007_07 VALUES LESS THAN (DATE'2007-08-01')
|
||||
, PARTITION Y2007_08 VALUES LESS THAN (DATE'2007-09-01')
|
||||
, PARTITION Y2007_09 VALUES LESS THAN (DATE'2007-10-01')
|
||||
, PARTITION Y2007_10 VALUES LESS THAN (DATE'2007-11-01')
|
||||
, PARTITION Y2007_11 VALUES LESS THAN (DATE'2007-12-01')
|
||||
, PARTITION Y2007_12 VALUES LESS THAN (DATE'2008-01-01')
|
||||
, PARTITION Y2008_01 VALUES LESS THAN (DATE'2008-02-01')
|
||||
, PARTITION Y2008_02 VALUES LESS THAN (DATE'2008-03-01')
|
||||
, PARTITION Y2008_03 VALUES LESS THAN (DATE'2008-04-01')
|
||||
, PARTITION Y2008_04 VALUES LESS THAN (DATE'2008-05-01')
|
||||
, PARTITION Y2008_05 VALUES LESS THAN (DATE'2008-06-01')
|
||||
, PARTITION Y2008_06 VALUES LESS THAN (DATE'2008-07-01')
|
||||
, PARTITION Y2008_07 VALUES LESS THAN (DATE'2008-08-01')
|
||||
, PARTITION Y2008_08 VALUES LESS THAN (MAXVALUE)
|
||||
)
|
||||
COMPRESS
|
||||
/
|
||||
|
||||
INSERT /*+ APPEND */ INTO &ppxuser..orders_range
|
||||
SELECT * FROM &oeuser..orders
|
||||
/
|
||||
|
||||
COMMIT;
|
||||
|
||||
EXEC DBMS_STATS.GATHER_TABLE_STATS('&ppxuser', 'ORDERS_RANGE');
|
||||
|
||||
Reference in New Issue
Block a user