Hash Table - For Pattern Matching
Shravani, July 27, 2011 - 7:27 am UTC
Hi Tom,
This is regarding the first question of this thread. I referred your book "Expert One On One Oracle" for the effective use of Hash Table. However I am
not clear whether I can use it for below requirement.
As a daily process, we are loading a inventory files which gives item with its unit. I am giving the dummy tables just for example purposes
The table structure is
create table item_details
(
stock_id number,
item_list varchar2(4000),
scheme_id varchar2(4000)
);
and records are
insert into item_details (stock_id, item_list) values (10, 'books,pen,pencil');
insert into item_details (stock_id, item_list) values (20, 'pen');
insert into item_details (stock_id, item_list) values (30, 'books,pencil');
insert into item_details (stock_id, item_list) values (40, 'books,pen');
insert into item_details (stock_id, item_list) values (50, 'books');
insert into item_details (stock_id, item_list) values (60, 'pencil');
insert into item_details (stock_id, item_list) values (70, 'cd-set,computer books,keyboard.monitor,mouse-pad,pen-drive');
insert into item_details (stock_id, item_list) values (80, 'books,keyboard.monitor,pen');
insert into item_details (stock_id, item_list) values (90, 'brush,paper,pen');
insert into item_details (stock_id, item_list) values (100, 'brush,pen');
commit;
Note - The Item List is always sorted alphabetically.
We have a set process to load this file on monthly basis and then transform the data into main tables.
As per new requirement, we will also get one more file which will have item lists and scheme code. We have designed below table
create table scheme_details
(
scheme_id number,
item_list varchar2(2000)
);
insert into scheme_details values (1, 'cd-set,pen,softwares,keyboard');
insert into scheme_details values (2, 'pencil,pen,books');
insert into scheme_details values (3, 'computer book,keyboard,mouse-pad,pen,pencil');
commit;
Now the requirement is to check the "item_list" from "scheme_details" and if any one item is matched with the "item_details.list" then append the
scheme id.
After the process records in "item_details" should be
STOCK_ID ITEM_LIST SCHEME_ID
-----------------------------------------------------------------------------------------------------------------
10 'books,pen,pencil' 1,2,3
20 'pen' 1,2,3
30 'books,pencil' 2,3
40 'books,pen' 1,2,3
50 'books' 2
60 'pencil' 3
70 'cd-set,computer books,keyboard.monitor,mouse-pad,pen-drive' 1,3
80 'books,keyboard.monitor,pen' 1,2,3
90 'brush,paper,pen' 1,2,3
100 'brush,pen' 1,2,3
The current number rows in "item_details" is > 1.2 M. And the estimated number of records in new "scheme_details" is around 50-60K.
We tried using the direct UPDATE but it is taking lot of time.
Can we use the hash-table for the pattern comparison? Can you please provide just the effectice PL-SQL design for such requirements?
Regards
Shravani
July 28, 2011 - 7:04 pm UTC
i hate your schema, i truly do.
what kind of person stores a delimited list? why? do you really really just want the most horrifically bad performance you can ever achieve? do you love writing lots of complex code to parse strings?
My answer would involve a redesign (no wait, it would involve an INITIAL design) and the delimited lists would disappear. Sorry, I have no magic for this, it is going to be painful.