通过混合分区方式较少模糊匹配的数据集,已达到提升性能的目的。
--混合分区方式
DATABASE:dwtest(210开发库)
--词搜索底层表
SQL> desc iquery.lpx_kw_tmp02
Name Type Nullable Default Comments
------------------ ------------- -------- ------- --------
KEYWORDS VARCHAR2(256) Y
COUNTRY_ID VARCHAR2(10) Y
COUNTRY_NAME VARCHAR2(256) Y
REGION_ID NUMBER Y
REGIN_NAME VARCHAR2(128) Y
PRE_REGIN_ID NUMBER Y
PRE_REGIN_ENAME VARCHAR2(128) Y
SRH_PV_THIS_5MON NUMBER Y
CATEGORY_LEAF_ID NUMBER Y
CATEGORY_ROOT_ID NUMBER Y
CATEGORY_LEVEL2_ID NUMBER Y
CATEGORY_LEVEL3_ID NUMBER Y
--按根级行业ID和大洲进行混合分区
CREATE TABLE iquery.lpx_kw_tmp02_bak1(
KEYWORDS VARCHAR2(256)
,REGIN_NAME VARCHAR2(128)
,CATEGORY_ROOT_ID NUMBER
,SRH_PV_THIS_5MON NUMBER
)PARTITION BY RANGE(CATEGORY_ROOT_ID) SUBPARTITION BY LIST(REGIN_NAME)
(
PARTITION p1 VALUES LESS THAN(10) TABLESPACE TBS_EN_DSS_2009
(
SUBPARTITION p1_asia VALUES('Asia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_north_america VALUES('North America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_western_europe VALUES('Western Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_middle_east VALUES('Middle East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_eastern_europe VALUES('Eastern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_australia VALUES('Australia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_south_america VALUES('South America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_northern_europe VALUES('Northern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_africa_south VALUES('Africa South') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_other VALUES('OTHER') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_africa_north VALUES('Africa North') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_caribbean_islands VALUES('Caribbean Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_new_zealand VALUES('New Zealand') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_africa_west VALUES('Africa West') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_africa_east VALUES('Africa East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_central_america VALUES('Central America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_pacific_islands VALUES('Pacific Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_africa_central VALUES('Africa Central') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_antarctica VALUES('Antarctica') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p1_default VALUES(DEFAULT) TABLESPACE TBS_EN_DSS_2009
),
PARTITION p2 VALUES LESS THAN(20) TABLESPACE TBS_EN_DSS_2009
(
SUBPARTITION p2_asia VALUES('Asia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_north_america VALUES('North America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_western_europe VALUES('Western Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_middle_east VALUES('Middle East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_eastern_europe VALUES('Eastern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_australia VALUES('Australia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_south_america VALUES('South America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_northern_europe VALUES('Northern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_africa_south VALUES('Africa South') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_other VALUES('OTHER') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_africa_north VALUES('Africa North') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_caribbean_islands VALUES('Caribbean Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_new_zealand VALUES('New Zealand') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_africa_west VALUES('Africa West') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_africa_east VALUES('Africa East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_central_america VALUES('Central America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_pacific_islands VALUES('Pacific Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_africa_central VALUES('Africa Central') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_antarctica VALUES('Antarctica') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p2_default VALUES(DEFAULT) TABLESPACE TBS_EN_DSS_2009
),
PARTITION p3 VALUES LESS THAN(30) TABLESPACE TBS_EN_DSS_2009
(
SUBPARTITION p3_asia VALUES('Asia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_north_america VALUES('North America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_western_europe VALUES('Western Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_middle_east VALUES('Middle East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_eastern_europe VALUES('Eastern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_australia VALUES('Australia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_south_america VALUES('South America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_northern_europe VALUES('Northern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_africa_south VALUES('Africa South') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_other VALUES('OTHER') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_africa_north VALUES('Africa North') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_caribbean_islands VALUES('Caribbean Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_new_zealand VALUES('New Zealand') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_africa_west VALUES('Africa West') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_africa_east VALUES('Africa East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_central_america VALUES('Central America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_pacific_islands VALUES('Pacific Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_africa_central VALUES('Africa Central') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_antarctica VALUES('Antarctica') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p3_default VALUES(DEFAULT) TABLESPACE TBS_EN_DSS_2009
),
PARTITION p4 VALUES LESS THAN(80) TABLESPACE TBS_EN_DSS_2009
(
SUBPARTITION p4_asia VALUES('Asia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_north_america VALUES('North America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_western_europe VALUES('Western Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_middle_east VALUES('Middle East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_eastern_europe VALUES('Eastern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_australia VALUES('Australia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_south_america VALUES('South America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_northern_europe VALUES('Northern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_africa_south VALUES('Africa South') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_other VALUES('OTHER') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_africa_north VALUES('Africa North') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_caribbean_islands VALUES('Caribbean Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_new_zealand VALUES('New Zealand') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_africa_west VALUES('Africa West') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_africa_east VALUES('Africa East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_central_america VALUES('Central America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_pacific_islands VALUES('Pacific Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_africa_central VALUES('Africa Central') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_antarctica VALUES('Antarctica') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p4_default VALUES(DEFAULT) TABLESPACE TBS_EN_DSS_2009
),
PARTITION p5 VALUES LESS THAN(999999999) TABLESPACE TBS_EN_DSS_2009
(
SUBPARTITION p5_asia VALUES('Asia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_north_america VALUES('North America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_western_europe VALUES('Western Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_middle_east VALUES('Middle East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_eastern_europe VALUES('Eastern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_australia VALUES('Australia') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_south_america VALUES('South America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_northern_europe VALUES('Northern Europe') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_africa_south VALUES('Africa South') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_other VALUES('OTHER') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_africa_north VALUES('Africa North') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_caribbean_islands VALUES('Caribbean Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_new_zealand VALUES('New Zealand') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_africa_west VALUES('Africa West') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_africa_east VALUES('Africa East') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_central_america VALUES('Central America') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_pacific_islands VALUES('Pacific Islands') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_africa_central VALUES('Africa Central') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_antarctica VALUES('Antarctica') TABLESPACE TBS_EN_DSS_2009,
SUBPARTITION p5_default VALUES(DEFAULT) TABLESPACE TBS_EN_DSS_2009
)
);
INSERT INTO iquery.lpx_kw_tmp02_bak1
SELECT keywords,
REGIN_NAME,
CATEGORY_ROOT_ID,
SUM(SRH_PV_THIS_5MON) AS SRH_PV_THIS_5MON
FROM iquery.lpx_kw_tmp02
WHERE CATEGORY_ROOT_ID IS NOT NULL --去除类目为空的记录
GROUP BY keywords,
REGION_ID,
REGIN_NAME,
CATEGORY_ROOT_ID;
COMMIT;
7799710 rows created.
SQL>
Commit complete.
SQL> select count(1) from iquery.lpx_kw_tmp02_bak1;
COUNT(1)
----------
7799710
--造测试数据
DROP TABLE iquery.lpx_kw_test;
CREATE TABLE iquery.lpx_kw_test TABLESPACE TBS_EN_DSS_2009
AS
SELECT SUBSTR(keywords, INSTR(keywords, ' ', 1)+1, INSTR(keywords, ' ', 1, 2) - INSTR(keywords, ' ', 1) - 1) AS kw, a.*
FROM iquery.lpx_kw_tmp02_bak1 a
WHERE length(keywords) - length(REPLACE(keywords, ' ', '')) > 2 AND ROWNUM < 100000 + 1;
--根据行业和大洲进行匹配
DROP TABLE iquery.lpx_kw_tmp03;
CREATE TABLE iquery.lpx_kw_tmp03(
KW VARCHAR2(256)
,REGIN_NAME VARCHAR2(128)
,CATEGORY_ROOT_ID NUMBER
,SRH_PV_THIS_5MON NUMBER
);
set serveroutput ON;
DECLARE
cnt NUMBER;
start_date DATE;
end_date DATE;
CURSOR c1
IS
select kw, keywords, regin_name, category_root_id FROM iquery.lpx_kw_test;
BEGIN
cnt := 0;
start_date := SYSDATE;
FOR ref_cursor IN c1
LOOP
INSERT INTO iquery.lpx_kw_tmp03
SELECT ref_cursor.kw
,ref_cursor.regin_name
,ref_cursor.category_root_id
,SUM(a.srh_pv_this_5mon) AS srh_pv_this_5mon
FROM iquery.lpx_kw_tmp02_bak1 a
WHERE a.keywords LIKE '%'||ref_cursor.kw||'%'
AND a.category_root_id = ref_cursor.category_root_id --根级行业
AND a.regin_name = ref_cursor.regin_name --买家所在大洲
GROUP BY ref_cursor.kw
,ref_cursor.regin_name
,ref_cursor.category_root_id;
COMMIT;
cnt := cnt + 1;
END LOOP;
end_date := SYSDATE;
DBMS_OUTPUT.PUT_LINE('total records:'||cnt);
DBMS_OUTPUT.PUT_LINE('total time(ms):'||ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60 * 1000));
DBMS_OUTPUT.PUT_LINE('avg time(ms):'||ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60 * 1000)/cnt);
END;
/
total records:1000
total time(ms):30000
avg time(ms):30
PL/SQL procedure successfully completed.
total records:10000
total time(ms):303000
avg time(ms):30.3
PL/SQL procedure successfully completed.
total records:100000
total time(ms):3182000
avg time(ms):31.82
PL/SQL procedure successfully completed.