Skip to content

Commit 4adb165

Browse files
Merge pull request #1238 from oracle-devrel/uschwinn-patch-31
Create fastlookup.sql
2 parents 7c188a7 + 0b213ff commit 4adb165

File tree

1 file changed

+70
-0
lines changed
  • data-platform/core-converged-db/fast-ingest-lookup/files

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
-- this script demonstrates the fast lookup usage in Oracle Database
2+
-- database release could be before 23ai
3+
4+
set feedback on
5+
set echo on
6+
7+
-- configure memmoptimize pool in container ROOT
8+
ALTER SYSTEM SET MEMOPTIMIZE_POOL_SIZE = 500M SCOPE=SPFILE;
9+
10+
-- restart the database
11+
startup force
12+
13+
-- check the setting
14+
15+
SHOW PARAMETER MEMOPTIMIZE_POOL_SIZE
16+
17+
pause
18+
-- privileges for SH to monitor execution plans
19+
grant select on v_$session to sh;
20+
grant select on v_$sql_plan to sh;
21+
grant select on v_$sql_plan_statistics_all to sh;
22+
grant select on v_$sql to sh;
23+
grant read on v_$sql to sh;
24+
25+
-- connect as SH user in PDB
26+
connect sh/&password@&pdb
27+
28+
-- drop table sales_tab
29+
drop table sales_tab;
30+
31+
-- create table SALES_TAB
32+
create table sh.sales_tab (
33+
sales_id NUMBER(6) primary key,
34+
prod_id NUMBER(6) not null,
35+
cust_id NUMBER not null,
36+
time_id DATE not null,
37+
quantity_sold NUMBER(3) not null,
38+
amount_sold NUMBER(10,2) not null);
39+
40+
-- insert data
41+
insert into sh.sales_tab (sales_id,prod_id, cust_id, time_id, quantity_sold, amount_sold)
42+
select rownum, PROD_ID, CUST_ID, TIME_ID, QUANTITY_SOLD, AMOUNT_SOLD from sh.sales;
43+
44+
select count(*) from sales_tab;
45+
46+
-- Now let's enable the feature for the data stored in SH.SALES_TAB.
47+
ALTER TABLE SH.SALES_TAB MEMOPTIMIZE FOR READ;
48+
49+
-- gather statistics
50+
execute dbms_stats.gather_table_stats('SH','SALES_TAB');
51+
52+
-- populate
53+
execute dbms_memoptimize.populate(schema_name=>'SH',table_name=>'SALES_TAB');
54+
55+
pause
56+
-- lets check with two queries
57+
set linesize window
58+
59+
-- this one will use memoptimize rowstore
60+
select * from sh.sales_tab where sales_id=5;
61+
62+
-- check the execution plan
63+
select * from dbms_xplan.display_cursor();
64+
65+
pause
66+
-- this one won't work
67+
select * from sh.sales_tab where sales_id<2;
68+
69+
-- check the execution plan
70+
select * from dbms_xplan.display_cursor();

0 commit comments

Comments
 (0)