Month: January 2008

2008 wishlist

Been a while, folks. Basically, a holiday trip with the family back to old Portugal, with a jaunt to Rome and Singapore on the way back.Of course while I was gone, all sorts of things happened:1- HJR has once again demolished his site. It’s a pity th…

2008 wishlist

Been a while, folks. Basically, a holiday trip with the family back to old Portugal, with a jaunt to Rome and Singapore on the way back.Of course while I was gone, all sorts of things happened:1- HJR has once again demolished his site. It’s a pity th…

Detect numbers with TRANSLATE() – Take two

Last week I wrote about using TRANSLATE to detect numbers in data Using The TRANSLATE() function…

Andrew Clarke at Radio Free Tooting pointed out the shortcomings of using TRANSLATE() to detect numbers.

As I said earlier, all I needed to do was detect if the characters in a string were all digits or not, and I wanted it to be very fast.

But Andrew’s remarks got me thinking – could translate be used to detect more complex numbers?

Here’s the short list of requirements:

* Detect integers
* Detect numbers with decimal point ( 4.6, 0.2, .7)
* Detect negative and positive ( leading + or – )
* Reject text with more than 1 ‘.’, such as an IP address ( 127.0.0.1 )
* Reject anything with alpha text

And comma’s are considered as text. 99,324.1 would be alpha.

If you need to do this on 10g, no problem, as a regular expression can handle it.

Fist create some test data:

drop table number_test;

create table number_test( alphacol varchar2(20));

insert into number_test values(‘.5’);
insert into number_test values(‘1’);
insert into number_test values(‘2’);
insert into number_test values(‘ 3’);
insert into number_test values(‘4 ‘);
insert into number_test values(‘3.14159’);
insert into number_test values(‘127.0.0.1’);
insert into number_test values(‘+34.45’);
insert into number_test values(‘-54.43’);
insert into number_test values(‘this is a test’);
insert into number_test values(‘th1s is 4 t3st’);
insert into number_test values(‘.’);
commit;

Now select only columns where the value is a number:

select alphacol
from number_test
where regexp_instr(trim(alphacol),’^[-+]?[0-9]*(\.?[0-9]+)?$’) > 0
order by 1

SQL> /

ALPHACOL
——————–
3
+34.45
-54.43
1
2
3.14159
4

7 rows selected.

That seems to work.

But what if you’re stuck doing this on 9i? REGEXP_INSTR is not available.

You can use the user defined function IS_NUMBER(), which works well, but is very slow if used on large amounts of data.

Might we be able to use and abuse the TRANSLATE() function to speed this up? Here’s a bit of convoluted SQL that works well on the limited test data:

select alphacol, alpha2
from
(
select alphacol,
— is there a sign +- ? – remove it
decode(substr(alpha2,1,1),
‘-‘,substr(alpha2,2),
‘+’,substr(alpha2,2),
alpha2
) alpha2
from (
select
alphacol,
— remove a single ‘.’ if it/they exists
replace(substr(alphacol,1,instr(alphacol,’.’)),’.’) || substr(alphacol,instr(alphacol,’.’)+1) alpha2
from (
select trim(alphacol) alphacol
from number_test
)
)
)
where substr(‘||||||||||||||||||||||||||||||||’,1,length(alpha2)) = translate(alpha2,’0123456789′,’||||||||||’)
/


(Sorry about formatting – I seem to lose all formatting when I paste SQL)

Output from this nasty bit of SQL is identical to that when using REGEXP_INSTR:

ALPHACOL ALPHA2
——————– —————————————-
.5 5
1 1
2 2
3 3
4 4
3.14159 314159
+34.45 3445
-54.43 5443

8 rows selected.

To make the TRANLATE() function do what is needed, a lot of data manipulation had to be done in the SQL. There is so much work being done now that it now takes nearly as long to run as does the IS_NUMBER() function, so there isn’t much point in using TRANSLATE().

Runstats results:

SQL> @th5
.047739 secs
.037447 secs
PL/SQL procedure successfully completed.

If nothing else, this was an interesting exercise.

Rolling invalidations

There have been discussions which I have seen related to the feature of auto invalidation in dbms_stats. A couple of references arehttp://forums.oracle.com/forums/thread.jspa?threadID=592771&tstart=30andhttp://www.orafaq.com/maillist/oracle-l/2006/10/1…

Rolling invalidations

There have been discussions which I have seen related to the feature of auto invalidation in dbms_stats. A couple of references are

http://forums.oracle.com/forums/thread.jspa?threadID=592771&tstart=30
and
http://www.orafaq.com/maillist/oracle-l/2006/10/10/0429.htm

I have tested the relevant parameter “_optimizer_invalidation_period” on 10.2.0.3 and believe that this is working as expected

Let us take the below testcase where the parameter (it is dynamic) is set to a value of 120

SQL> show parameter optimizer_inva

NAME TYPE VALUE
———————————— ———– ——————————
_optimizer_invalidation_period integer 120

We have the following sql statement

11:00:00 SQL> select * from source where rownum
OBJ# LINE SOURCE
———- ———- —————————————————————————
194107 171 — *Action: Start a new job, or attach to an existing job that has a

1 row selected.

Elapsed: 00:00:00.12
11:00:00 SQL> select * from source where rownum
OBJ# LINE SOURCE
———- ———- —————————————————————————
194107 171 — *Action: Start a new job, or attach to an existing job that has a

1 row selected.

Elapsed: 00:00:00.00
11:00:00 SQL> select a.child_number,LAST_LOAD_TIME, to_char(LAST_ACTIVE_TIME,’dd-mon-yyyy hh24:mi:ss’) ,b.invalidations from
v$SQL_SHARED_CURSOR a, v$sql b where a.sql_id=’954g5yyw5tn1s’ and a.child_address=b.child_address ;

CHILD_NUMBER LAST_LOAD_TIME TO_CHAR(LAST_ACTIVE_ INVALIDATIONS
———— ——————- ——————– ————-
0 2008-01-29/11:00:00 29-jan-2008 11:00:00 0

1 row selected.

Elapsed: 00:00:00.14
11:00:00 SQL>
11:00:00 SQL> select executions, invalidations,child_number from v$sql where sql_id=’954g5yyw5tn1s’;

EXECUTIONS INVALIDATIONS CHILD_NUMBER
———- ————- ————
2 0 0

1 row selected.

Now we gather stats on the table with the auto_invalidate parameter passed to the API.

11:00:00 SQL> exec dbms_stats.gather_table_stats(‘REGOFA’,’SOURCE’,no_invalidate => DBMS_STATS.AUTO_INVALIDATE);

PL/SQL procedure successfully completed.

Elapsed: 00:00:01.50

Then we keep executing the sql statement of interest to check when the new cursor will be generated.

Elapsed: 00:00:01.50
11:00:13 SQL> select a.child_number,LAST_LOAD_TIME, to_char(LAST_ACTIVE_TIME,’dd-mon-yyyy hh24:mi:ss’) ,b.invalidations from
v$SQL_SHARED_CURSOR a, v$sql b where a.sql_id=’954g5yyw5tn1s’ and a.child_address=b.child_address ;

CHILD_NUMBER LAST_LOAD_TIME TO_CHAR(LAST_ACTIVE_ INVALIDATIONS
———— ——————- ——————– ————-
0 2008-01-29/11:00:00 29-jan-2008 11:00:09 0

1 row selected.

Elapsed: 00:00:00.05
11:00:13 SQL> select executions, invalidations,child_number from v$sql where sql_id=’954g5yyw5tn1s’;

EXECUTIONS INVALIDATIONS CHILD_NUMBER
———- ————- ————
3 0 0

1 row selected.

Elapsed: 00:00:00.00
11:00:13 SQL> select * from v$sql_shared_cursor where sql_id=’954g5yyw5tn1s’;

SQL_ID ADDRESS CHILD_ADDRESS CHILD_NUMBER U S O O S L S E B P
————- —————- —————- ———— – – – – – – – – – –
I S T A B D L T R I I R L I O S M U T N F A I T D L D B P C S R P T M B M R O P
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
M F L
– – –
954g5yyw5tn1s 00000007D3BBCBD8 00000007D5644028 0 N N N N N N N N N N
N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N
N N N

1 row selected.
…….
11:00:37 SQL> select * from source where rownum
OBJ# LINE SOURCE
———- ———- —————————————————————————
194107 171 — *Action: Start a new job, or attach to an existing job that has a

1 row selected.

Elapsed: 00:00:00.01
11:00:39 SQL> select a.child_number,LAST_LOAD_TIME, to_char(LAST_ACTIVE_TIME,’dd-mon-yyyy hh24:mi:ss’) ,b.invalidations from
v$SQL_SHARED_CURSOR a, v$sql b where a.sql_id=’954g5yyw5tn1s’ and a.child_address=b.child_address ;

CHILD_NUMBER LAST_LOAD_TIME TO_CHAR(LAST_ACTIVE_ INVALIDATIONS
———— ——————- ——————– ————-
0 2008-01-29/11:00:00 29-jan-2008 11:00:25 0
1 2008-01-29/11:00:37 29-jan-2008 11:00:37 0

2 rows selected.

Elapsed: 00:00:00.04
11:00:39 SQL> select executions, invalidations,child_number from v$sql where sql_id=’954g5yyw5tn1s’;

EXECUTIONS INVALIDATIONS CHILD_NUMBER
———- ————- ————
7 0 0
1 0 1

2 rows selected.

Elapsed: 00:00:00.00
11:00:39 SQL> select * from v$sql_shared_cursor where sql_id=’954g5yyw5tn1s’;

SQL_ID ADDRESS CHILD_ADDRESS CHILD_NUMBER U S O O S L S E B P
————- —————- —————- ———— – – – – – – – – – –
I S T A B D L T R I I R L I O S M U T N F A I T D L D B P C S R P T M B M R O P
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
M F L
– – –
954g5yyw5tn1s 00000007D3BBCBD8 00000007D5644028 0 N N N N N N N N N N
N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N
N N N

954g5yyw5tn1s 00000007D3BBCBD8 00000007D3753DC0 1 N N N N N N N N N N
N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N Y N N
N N N

So somewhere between 11:00:00 and 11:00:39 (within the 2 minute window) a new child cursor has been generated with roll_invalid_mismatch set to ‘Y”

I have tested for the following values of _optimizer_invalidation_period and I see consistent results

120
210
600
1800
18000

Hence this would be an ideal way to avoid a hard parse storm

An upper bound of the transactions throughputs

Capacity planning fundamental laws are seldom used to identify benchmark flaws, although some of these laws are almost trivial. Worse, some performance assessments provide performance outputs which are individually commented without even realizing that physical laws bind them together. Perhaps the simplest of them all is the Utilization law, which states that the utilization of […]

Tag flood

  Amid the tag furry, I was tagged some days ago by Jeff Moss so I’ll have to give some pieces of information about myself presumably of low interest to most. I had not put any personal information on my blog, so here are 8 of them which I’ll keep short anyway: I come from […]

The blog tagging thing

During the last few days lots of Oracle bloggers have been busy tagging each other and posting eight unknown things about themselves. I was also tagged by some friends and was asked to post eight things about myself. I have never forwarded any chain e…

TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569