I have a static list of 100,000 values in an array, given a string I
generate a hashcode and return an item from this array. I could join to
another table but everything has to be done in a function.
e.g select myFunc(field1) from myTable;
Any ideas what Oracle approach (language) would be best for this? So
far I've tried done the following.
PL/SQL Table or Varray instantiated within a package (Natively compiled
and interpreted)
4 seconds to translate 160k records.
Java static constants across multiple classes (constant pool size limit
would be reached with a single class)
33 seconds to translate 160k records
and calling lower() instead of my function takes 1 second to pass 160k
records, if i put lower in my package it also takes 3-4 seconds.
So any ideas, e.g. if I write the function in C and link it, would that
work well.
Thanks in advance.
>I have a static list of 100,000 values in an array, given a string I
>generate a hashcode and return an item from this array. I could join to
>another table but everything has to be done in a function.
Why? issuing select in an 'embedded' function (also an implicit join)
usually precludes efficient execution paths and necessarily results in
abysmal performance. Also your C idea will result in an *external*
function, with additional overhead (communicating with the listener)
--
Sybrand Bakker, Senior Oracle DBA
There isn't a select going on in the embedded function, the function is
completely self contained. The query plan's so far with the PL/SQL
option match the same query using lower() or some type of encyption()
function
I've read the thread and now returned to your original post. I must
confess to being confused. Waht does the array with 100,000 values and
the hash code have to do with SELECT myFunct? It is far from clear.
And why 100,000 records? What "needs" 100,000 records at one time and
why?
I'd be heading straight for a syntax like this:
BEGIN
OPEN c;
LOOP
FETCH c BULK COLLECT INTO l_data LIMIT p_array_size;
-- stuff here
EXIT WHEN c%NOTFOUND;
END LOOP;
CLOSE c;
And set p_array_size to 100-500.
--
Daniel A. Morgan
http://www.psoug.org
damo...@x.washington.edu
(replace x with u to respond)
Instead of containing things in an array perhaps you really want to use
an oracle hash table where you can use oracle to "randomize" or hash to
a block based on how you define the hash. Performance in that case
will be much better.
Try checking in the asktom.oracle.com site and do some searches using
hash and select you should fine some helpful information.
-- pseudo-code
package X
TYPE itemStore IS TABLE OF myTable.field1%TYPE INDEX BY
BINARY_INTEGER;
items itemStore;
-- fetch value from items based on hash of value
function myFund(arg0 IN myTable.field1%TYPE) return
myTable.field1%TYPE
as
return items(mod(dbms_utility.hash(arg0,0,1000000),100000)+1);
end;
-- does this on initial call only
begin
select field1 BULK COLLECT into items from seedTable;
end;
Thanks
> So any ideas, e.g. if I write the function in C and link it, would that
> work well.
It depends on how you write it. If it is well written, it would work well.
If it isn't, it wouldn't.
--
Demagogue: One who preaches a doctrine he knows to be untrue to
men he knows to be idiots.
H.L. Mencken
9.2 and above, your strings *can* be the index into a plsql table if
that helps.
hth
connor
--
Connor McDonald
Co-author: "Mastering Oracle PL/SQL - Practical Solutions"
Co-author: "Oracle Insight - Tales of the OakTable"
web: http://www.oracledba.co.uk
web: http://www.oaktable.net
email: connor_...@yahoo.com
"Semper in excremento, sole profundum qui variat."
------------------------------------------------------------