oracle


I have a Procedure that it takes way too long, what can I do about it?


I have a table that store the GPS data from about 80 vehicle. This table keeps GPS transmission for each 30 seconds. I need to delete some data and keep the GPS transitions for each 60 seconds, at least. So I have the following procedure that read each row, for each det_id, and when the current row is less than 59 seconds from the previous row, then the the FLAG column is updated with '0'. After this I will delete those rows with FLAG = '0'.
The problem is this Procedure takes so long (about 40 hours for 3 million records).
I did an index with ts_id and ts_dh but it doesn't change so much.
How can improve this procedure?
Do I need to do a especial index?
Am I missing something in my procedure?
DECLARE
WriteZero NUMBER:= 0;
CURSOR CUR_TABLE_SOURCE IS
SELECT
FLAG, ANT_TS_DH,ts_id,TS_DH,TS_DHS
FROM TABLE_SOURCE
where ts_id = in_ts_id
order by ts_id, TS_DH;
V_count number:=0;
V_Ant number:=0;
V_TABLESOURCE_REC CUR_TABLE_SOURCE%ROWTYPE;
BEGIN
OPEN CUR_TABLE_SOURCE; --- for update;
loop
FETCH CUR_TABLE_SOURCE INTO V_TABLESOURCE_REC;
EXIT WHEN CUR_TABLE_SOURCE%NOTFOUND;
V_count := V_count + 1;
Begin
IF V_TABLESOURCE_REC.ANT_TS_DH is null then
UPDATE TABLE_SOURCE SET
FLAG = '1'
WHERE ANT_TS_DH = V_TABLESOURCE_REC.ANT_TS_DH
AND ts_id = V_TABLESOURCE_REC.ts_id
AND TS_DHS = V_TABLESOURCE_REC.TS_DHS;
commit;
V_Ant :=1;
ELSE
IF V_TABLESOURCE_REC.ANT_TS_DH + 59/86400 >= V_TABLESOURCE_REC.TS_DH THEN
IF V_Ant = 1 THEN
UPDATE TABLE_SOURCE SET
FLAG = '0' -- delete data with flag = 0
WHERE ANT_TS_DH = V_TABLESOURCE_REC.ANT_TS_DH
AND ts_id = V_TABLESOURCE_REC.ts_id
AND TS_DHS = V_TABLESOURCE_REC.TS_DHS;
V_Ant :=0;
commit;
ELSE
UPDATE TABLE_SOURCE SET
FLAG = '1' -- keep data with flag = 0
WHERE ANT_TS_DH = V_TABLESOURCE_REC.ANT_TS_DH
AND ts_id = V_TABLESOURCE_REC.ts_id
AND TS_DHS = V_TABLESOURCE_REC.TS_DHS;
V_Ant :=1;
commit;
End If;
ELSE
UPDATE TABLE_SOURCE SET
FLAG = '1'
WHERE ANT_TS_DH = V_TABLESOURCE_REC.ANT_TS_DH
AND ts_id = V_TABLESOURCE_REC.ts_id
AND TS_DHS = V_TABLESOURCE_REC.TS_DHS;
V_Ant :=1;
commit;
End If;
End If;
End;
END LOOP;
CLOSE CUR_TABLE_SOURCE;
COMMIT;
END;
This is the table_source:
TS_ID TS_DH LATI LONG
----- --------------------- ---------- ----------
3412 15-DEC-16 11.05.09 AM 11.42341 -81.95251
3412 15-DEC-16 11.05.39 AM 11.42344 -81.92435
3412 15-DEC-16 11.06.09 AM 11.43567 -81.85355
3412 15-DEC-16 11.06.39 AM 11.47851 -81.95246
3412 15-DEC-16 11.07.10 AM 11.45123 -81.63451
3412 15-DEC-16 11.07.40 AM 11.43451 -81.95351
3412 15-DEC-16 11.08.10 AM 11.45251 -81.46785
3412 15-DEC-16 11.08.40 AM 11.45678 -81.95551
3412 15-DEC-16 11.09.10 AM 11.43451 -81.93241
3412 15-DEC-16 11.09.40 AM 11.45456 -81.95251
3412 15-DEC-16 11.10.10 AM 11.42890 -81.95451
3412 15-DEC-16 11.15.40 AM 11.43451 -81.95351
3412 15-DEC-16 11.16.10 AM 11.45251 -81.46785
3412 15-DEC-16 11.16.40 AM 11.45678 -81.95551
3412 15-DEC-16 11.17.10 AM 11.43451 -81.93241
3412 15-DEC-16 11.17.40 AM 11.45456 -81.95251
3412 15-DEC-16 11.18.10 AM 11.42890 -81.95451

Related Links

Learning Oracle and GeoSpatial Systems
Is it a good idea to use Oracle 11g Client against a 10g database for Oracle Advanced Queuing?
Build a Oracle ADF application jar file using Ant
Changing graphics item in a canvas
Something unknown happened with a simple CREATE statement in Oracle 9i
PL/SQL noob syntax Error [closed]
My oracle merge does not work
Migrating changes from a dev APEX app to production?
SQLJ in Netbeans
RMAN not starting
Return collection from packaged function for use in select
JBoss 7 Spring Oracle connection pooling
Oracle Add a new member function/procedure to an object type
oracle portal and sso
Inserting records into one table coming from two tabs in a Oracle form
Oracle: Bottom-up delete

Categories

HOME
qt
automapper
keyboard
add-on
biztalk
azure-data-lake
video-streaming
facebook-android-sdk
specifications
anchor
jpa-criteria
fasm
google-awareness
jpa-2.0
uima
string-formatting
bazaar
fluent-migrator
acl
device
router
unrar
hdmi
oracleforms
xenapp
tightvnc
series
rspec-rails
cloveretl
textmate2
netstat
formsauthenticationticket
pdfnet
unification
selenide
oauth2
suds
word-cloud
vesta
kitura
webalizer
lightning-workbench
openstack-glance
simple-schema
gtk#
winmerge
kendo-treeview
wildfly-9
finder
ternary-operator
elastic4s
cefpython
metabase
xcode6.4
nclam
zynq
nsdata
powerpoint-2013
uibinder
swiffy
onepage-checkout
wif4.5
outlook.com
stack-smash
apache-commons-digester
nastran
dnx50
bjam
auto-generate
360-degrees
alwayson
com0com
sql-processor
lifetime
encryption-symmetric
configurable-product
image-rotation
berkeley-db-xml
mobile-country-code
squeezebox
box2dweb
forceclose
sql-function
nodeload
radius-protocol
flipboard
progress-db
mute
acitree
jquery-transit
tnt4j
pacman
sly-scroller
rikulo
proc-open
tridion-2011
stretch
kaazing
struts2-s2hibernate
qtextbrowser
snackjs
botnet
kohana-auth
j2mepolish
yahoo-maps
main-method
fuzzy-comparison
downcasting
code-camp
rendering-engine

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App