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

How to drop Parent table without deleting or dropping constraints on child table in Oracle
Retrieve increments of rows from multiple rows [duplicate]
Oracle service Bus protocol transport in proxy
Does converting Oracle .rdf files to .rep do anything different than changing the extension?
Denying Access To Oracle Database via tools like Toad, SQL Developer using Request Based Authentication
Oracle XE 11g R2 Screen
Oracle DBMS_LOB package OPEN procedure fails
ORACLE PL SQL : Select all and process every records
Oracle Group by salary range(0-999,1000-1999,2000-2999,…) [closed]
Parent element ID and full element path as result of Xpath query on XMLTYPE table
Securely changing Oracle DB passwords from JDBC [closed]
Why am I able to use a character that's not part of a charset (windows-1252)?
Exporting Oracle View into XML using XSD
Automating SQL Developer Generate Doc
ASM and ORACLE switching environments?
ETL-ORACLE DATA INTEGRATOR

Categories

HOME
yaml
vagrant
facebook-messenger
angular-ui-grid
xcode8.1
android-fragments
long-integer
writefile
swi-prolog
portable-class-library
stored-procedures
firebase-database
phpseclib
kurento
wine
sql-injection
dma
android-5.1.1-lollipop
c#-7.0
android-custom-view
qa
crud
annotation-processing
cube
javax.persistence
xenapp
actframework
epplus
counting
char-pointer
dreamfactory
subclassing
cargo
uivisualeffectview
tidal-scheduler
assemblies
task-parallel-library
utf
nothing
scala-breeze
non-linear-regression
spring.net
mura
dtd
rcharts
jenkins-workflow
ioctl
largenumber
apache-commons-digester
nette
embeddedwebserver
ampersand
innerhtml
signed
mod-auth-openidc
smacss
mobile-country-code
siena
prism.js
nodeload
gpu-programming
meteorite
smips
unrealscript
coalesce
libxml-js
jquery-lazyload
ui-design
semicolon
cmath
user-forums
semantic-merge
zend-pdf
audiotoolbox
java.lang.class
netstream
gwt-celltable
mvcrecaptcha
vows
ognl
chunking
projectpier
subtext
rakudo
gui-designer
isapi-redirect
html-generation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App