SLOW Query ... Need help improving performance
Database: Oracle 8i
Note: I don't have a whole lot of experience with writing queries, so please forgive me for any dumb mistakes I most likely made.
I have a query in which I have a SUM in two levels. I think this is probably the root cause of the very slow performance of the query. However, I just don't see any way around it, and can't come up with any other ways to speed up the query. The query itself only returns one line, the summary line. And, by slow, I mean it can take up to an hour or two. This is a query I need to run multiple times, based on some parameters that I cannot query from a database.
The query basically calculates the current unit cost of a part. It has to sum up the issue cost of the part (cost of material issued to the part's order), the actual dollars put into a part (labor, etc.), and the burden dollars associated with the part. This sum has to be divided by the total quantity of parts completed on the part's order to get the unit cost. I have to account for the possibility that the quantity complete is 0, so that I don't end up dividing by 0.
Below is my query, and sample data for it:
SELECT a.part_nbr
, a.mo_nbr
, a.unit_iss_cost
, CASE
WHEN a.qty_complete_ind ='Nonzero'
THEN SUM(a.act_dlrs/a.qty_complete)
ELSE 0
END AS unit_dlrs
, CASE
WHEN a.qty_complete_ind ='Zero'
THEN SUM(a.act_dlrs)
ELSE 0
END AS qty_0_dlrs
FROM ( SELECT act.part_nbr AS part_nbr
, act.order_nbr || '-' || act.sub_order_nbr AS mo_nbr
, ic.unit_iss_cost AS unit_iss_cost
, SUM (
act.act_dlrs_earned +
act.act_brdn_dls_earned +
act.tool_dlrs_earned +
act.act_fix_brdn_dls_ea
) AS act_dlrs
, ord.qty_complete AS qty_complete
, CASE
WHEN ord.qty_complete <>0
THEN 'Nonzero'
ELSE 'Zero'
END AS qty_complete_ind
FROM ACT act
, ISSUE_COST ic
, ORD ord
WHERE ord.ord_nbr =act.order_nbr AND
ord.sub_ord_nbr =act.sub_order_nbr AND
ord.major_seq_nbr =act.maj_seq_nbr AND
ic.ord_nbr =act.order_nbr AND
ic.sub_ord_nbr =act.sub_order_nbr AND
(act.order_nbr =LPAD(?,10,'0')) AND
(act.sub_order_nbr =LPAD(?,3,'0')) AND
(act.activity_date <=?)
GROUP BY act.part_nbr
, act.order_nbr || '-' || act.sub_order_nbr
, act.maj_seq_nbr
, ord.qty_complete
, ic.unit_iss_cost
) a
GROUP BY a.part_nbr
, a.mo_nbr
, a.unit_iss_cost
, a.qty_complete_ind
CREATE TABLE ACT
creation_date date
, c_id number (5,0)
, part_nbr varchar(25)
, order_nbr varchar(10)
, sub_order_nbr varchar(3)
, maj_seq_nbr varchar(4)
, act_dlrs_earned number (15,2)
, act_brdn_dls_earned number (15,2)
, tool_dlrs_earned number (15,2)
, act_fix_brdn_dls_ea number (15,2)
, activity_date date
CONSTRAINT ACT_PK
PRIMARY KEY (creation_date, c_id)
);--Please note, issue_cost is actually a view, not a table, but by itself it runs very quickly
CREATE TABLE ISSUE_COST
unit_iss_cost number(15,2)
, ord_nbr varchar(10)
, sub_ord_nbr varchar(3)
);--Please note, ord table has a couple of foreign keys that I did not mention
CREATE TABLE ORD
ord_nbr varchar(10)
, sub_ord_nbr varchar(3)
, major_seq_nbr varchar(4)
, qty_complete number (13,4)
);Sample tables:
ACT
creation_date c_id part_nbr order_nbr sub_order_nbr maj_seq_nbr act_dlrs_earned act_brdn_dls_earned tool_dlrs_earned act_fix_brdn_dls_ea activity_date
01/02/2000 12345 ABC-123 0000012345 001 0010 10.00 20.00 0.00 0.00 01/01/2000
01/02/2000 12345 XYZ-987 0000054321 001 0030 100.00 175.00 10.00 10.00 01/01/2000
01/03/2000 12347 ABC-123 0000012345 001 0020 25.00 75.00 5.00 1.00 01/02/2000
01/03/2000 12348 ABC-123 0000012345 001 0020 75.00 120.00 25.00 5.00 01/02/2000
01/03/2000 12349 XYZ-987 0000054321 001 0050 50.00 110.00 0.00 0.00 01/02/2000
01/04/2000 12350 ABC-123 0000012345 001 0030 25.00 40.00 0.00 0.00 01/03/2000
ISSUE_COST
unit_iss_cost ord_nbr sub_ord_nbr
125.00 0000012345 001
650.00 0000054321 001
ORD
ord_nbr sub_ord_nbr major_seq_nbr qty_complete
0000012345 001 0010 10
0000012345 001 0020 10
0000012345 001 0030 0
0000054321 001 0030 20
0000054321 001 0050 19If insert statements are needed for the sample tables, let me know and I'll go re-figure out how to write them. (I only have read-only access to the database I'm querying, so creating tables and inserting values aren't things I ever do).
Thanks in advance!
For diagnosing where the time of your query is being spent, we don't need create table and insert statements. If we execute your query with only a handful of rows, the query will be very fast. What we do need to know, is the plan the optimizer takes to compute your result set, and the cardinalities of each step.
Please read When your query takes too long ... carefully and post the full explain plan and tkprof output.
Regards,
Rob.
Similar Messages
-
How to tune this query for the improve performance ?
Hi All,
How to tune this query for the improve performance ?
select a.claim_number,a.pay_cd,a.claim_occurrence_number,
case
when sum(case
when a.payment_status_cd ='0'
then a.payment_est_amt
else 0
end
)=0
then 0
else (sum(case
when a.payment_status_cd='0'and a.payment_est_amt > 0
then a.payment_est_amt
else 0
end)
- sum(case
when a.payment_status_cd<>'0'
then a.payment_amt
else 0
end))
end as estimate
from ins_claim_payment a
where a.as_of_date between '31-jan-03' and '30-aug-06'
and ( a.data_source = '25' or (a.data_source between '27' and '29'))
and substr(a.pay_cd,1,1) IN ('2','3','4','8','9')
group by a.claim_number, a.pay_cd, a.claim_occurrence_number
Thank you,
MckaMcka
As well as EXPLAIN PLAN, let us know what proportion of rows are visited by this query. It may be that it is not using a full table scan when it should (or vice versa).
And of course we'd need to know what indexes are available, and how selective they are for the predicated you have in this query ...
Regards Nigel -
Need to improve Performance of select...endselect query
Hi experts,
I have a query in my program like below with inner join of 3 tables.
In my program used select....endselect again inside this select...endselect statements used..
While executing in production taking lot of time to fetch records. Can anyone suggest to improve performance of below query urgently...
Greatly appreciated ur help...
SELECT MVKEDWERK MVKEMATNR MVKEVKORG MVKEVTWEG MARA~MATNR
MARAMTART ZM012MTART ZM012ZLIND ZM012ZPRICEREF
INTO (MVKE-DWERK , MVKE-MATNR , MVKE-VKORG , MVKE-VTWEG , MARA-MATNR
, MARA-MTART , ZM012-MTART , ZM012-ZLIND , ZM012-ZPRICEREF )
FROM ( MVKE
INNER JOIN MARA
ON MARAMATNR = MVKEMATNR
INNER JOIN ZM012
ON ZM012MTART = MARAMTART )
WHERE MVKE~DWERK IN SP$00004
AND MVKE~MATNR IN SP$00001
AND MVKE~VKORG IN SP$00002
AND MVKE~VTWEG IN SP$00003
AND MARA~MTART IN SP$00005
AND ZM012~ZLIND IN SP$00006
AND ZM012~ZPRICEREF IN SP$00007.
%DBACC = %DBACC - 1.
IF %DBACC = 0.
STOP.
ENDIF.
CHECK SP$00005.
CHECK SP$00004.
CHECK SP$00001.
CHECK SP$00002.
CHECK SP$00003.
CHECK SP$00006.
CHECK SP$00007.
clear Check_PR00.
select * from A004
where kappl = 'V'
and kschl = 'PR00'
and vkorg = mvke-vkorg
and vtweg = mvke-vtweg
and matnr = mvke-matnr
and DATAB le sy-datum
and DATBI ge sy-datum.
if sy-subrc = 0.
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
Check_PR00 = konp-kbetr.
endif.
endselect.
endif.
endselect.
CHECK SP$00008.
clear Check_ZPR0.
select * from A004
where kappl = 'V'
and kschl = 'ZPR0'
and vkorg = mvke-vkorg
and vtweg = mvke-vtweg
and matnr = mvke-matnr
and DATAB le sy-datum
and DATBI ge sy-datum.
if sy-subrc = 0.
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
Check_ZPR0 = konp-kbetr.
endif.
endselect.
endif.
endselect.
CHECK SP$00009.
clear ZFMP.
select * from A004
where kappl = 'V'
and kschl = 'ZFMP'
and vkorg = mvke-vkorg
and vtweg = mvke-vtweg
and matnr = mvke-matnr
and DATAB le sy-datum
and DATBI ge sy-datum.
if sy-subrc = 0.
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
ZFMP = konp-kbetr.
endif.
endselect.
endif.
endselect.
CHECK SP$00010.
clear mastercost.
clear ZDCF.
select * from A004
where kappl = 'V'
and kschl = 'ZDCF'
and vkorg = mvke-vkorg
and vtweg = mvke-vtweg
and matnr = mvke-matnr
and DATAB le sy-datum
and DATBI ge sy-datum.
if sy-subrc = 0.
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
ZDCF = konp-kbetr.
endif.
endselect.
endif.
endselect.
CHECK SP$00011.
clear masterprice.
clear Standardcost.
select * from mbew
where matnr = mvke-matnr
and bwkey = mvke-dwerk.
Standardcost = mbew-stprs.
mastercost = MBEW-BWPRH.
masterprice = mBEW-BWPH1.
endselect.
ADD 1 TO %COUNT-MVKE.
%LINR-MVKE = '01'.
EXTRACT %FG01.
%EXT-MVKE01 = 'X'.
EXTRACT %FGWRMVKE01.
ENDSELECT.
best rgds..
hari..Hi there.
Some advices:
- why going to MVKE first and MARA then? You will find n rows in MVKE for 1 matnr, and then go n times to the same record in MARA. Do the oposite, i.e, go first to MARA (1 time per matnr) and then to MVKE.
- avoid select *, you will save time.
- use trace or measure performance in tcodes ST05 and SM30.
- replace:
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
Check_ZPR0 = konp-kbetr.
endif.
endselect.
by
select * from konp
where knumh = a004-knumh.
Check_ZPR0 = konp-kbetr.
exit.
endselect.
Here, if I understood, you only need to atribute kbetr value to Check_ZPR0 if selecting anything (don't need the IF because if enters in select, subrc always equal to 0, and also don't need to do it several times from same a004-knumh - reason for the EXIT.
Hope this helps.
Regards.
Valter Oliveira.
Edited by: Valter Oliveira on Jun 5, 2008 3:16 PM -
Need help in Performance tuning for function...
Hi all,
I am using the below algorithm for calculating the Luhn Alogorithm to calculate the 15th luhn digit for an IMEI (Phone Sim Card).
But the below function is taking about 6 min for 5 million records. I had 170 million records in a table want to calculate the luhn digit for all of them which might take up to 4-5 hours.Please help me performance tuning (better way or better logic for luhn calculation) to the below function.
A wikipedia link is provided for the luhn algorithm below
Create or Replace FUNCTION AddLuhnToIMEI (LuhnPrimitive VARCHAR2)
RETURN VARCHAR2
AS
Index_no NUMBER (2) := LENGTH (LuhnPrimitive);
Multiplier NUMBER (1) := 2;
Total_Sum NUMBER (4) := 0;
Plus NUMBER (2);
ReturnLuhn VARCHAR2 (25);
BEGIN
WHILE Index_no >= 1
LOOP
Plus := Multiplier * (TO_NUMBER (SUBSTR (LuhnPrimitive, Index_no, 1)));
Multiplier := (3 - Multiplier);
Total_Sum := Total_Sum + TO_NUMBER (TRUNC ( (Plus / 10))) + MOD (Plus, 10);
Index_no := Index_no - 1;
END LOOP;
ReturnLuhn := LuhnPrimitive || CASE
WHEN MOD (Total_Sum, 10) = 0 THEN '0'
ELSE TO_CHAR (10 - MOD (Total_Sum, 10))
END;
RETURN ReturnLuhn;
EXCEPTION
WHEN OTHERS
THEN
RETURN (LuhnPrimitive);
END AddLuhnToIMEI;
http://en.wikipedia.org/wiki/Luhn_algorithmAny sort of help is much appreciated....
Thanks
RedeThere is a not needed to_number function in it. TRUNC will already return a number.
Also the MOD function can be avoided at some steps. Since multiplying by 2 will never be higher then 18 you can speed up the calculation with this.
create or replace
FUNCTION AddLuhnToIMEI_fast (LuhnPrimitive VARCHAR2)
RETURN VARCHAR2
AS
Index_no pls_Integer;
Multiplier pls_Integer := 2;
Total_Sum pls_Integer := 0;
Plus pls_Integer;
rest pls_integer;
ReturnLuhn VARCHAR2 (25);
BEGIN
for Index_no in reverse 1..LENGTH (LuhnPrimitive) LOOP
Plus := Multiplier * TO_NUMBER (SUBSTR (LuhnPrimitive, Index_no, 1));
Multiplier := 3 - Multiplier;
if Plus < 10 then
Total_Sum := Total_Sum + Plus ;
else
Total_Sum := Total_Sum + Plus - 9;
end if;
END LOOP;
rest := MOD (Total_Sum, 10);
ReturnLuhn := LuhnPrimitive || CASE WHEN rest = 0 THEN '0' ELSE TO_CHAR (10 - rest) END;
RETURN ReturnLuhn;
END AddLuhnToIMEI_fast;
/My tests gave an improvement for about 40%.
The next step to try could be to use native complilation on this function. This can give an additional big boost.
Edited by: Sven W. on Mar 9, 2011 8:11 PM -
Need to improve performance for bex queries
Dear Experts,
Here we have bex queries buit on BW infoset, further infoset is buit on 2 dsos and 4 infoobjects.
we have built secondary indices to the two dso assuming will improve performance, but still query execution time is very long.
Could you suggest me on this.
Thanks in advance,
MannuHI,
Thanks for the repsonse.
But as I have mentioned the infoset is based on DSOs and Infoobjects. So we could not perform on aggregates.
in RSRT
I have tried look in read mode of the query i.e. in 'x', which is also valid as qurey needs to fetch huge data.
Could you pls look into other possible areas, in order to improve this.
Thanks in advance,
Mannu -
Yosemite made my MacBook Pro so slow. Need help.
I Upgraded my MBP (2012), from Mavericks to Yosemite and it slowed my computer down to the point where it became unusable. I repaired the permissions, and even reinstalled Yosemite but it didn't help. My MBP is crawling and I'm hoping someone can walk me through a solution. Need help.
SIgned,
YoseMighty SlowProblem description:
MacBook Pro (mid 2012) is running super slow since I upgraded to Yosemite. Used CleanMyMac2 and freed up 22G. Verified and repaired disk permissions. Re-installed Yosemite and still, it is running dead slow. Windows take between 45-60 seconds to open, files are slow to appear…generally just slow and unresponsive.
EtreCheck version: 2.0.6 (91)
Report generated October 19, 2014 at 8:42:19 PM EDT
Hardware Information: ℹ️
MacBook Pro (13-inch, Mid 2012) (Verified)
MacBook Pro - model: MacBookPro9,2
1 2.5 GHz Intel Core i5 CPU: 2-core
8 GB RAM Upgradeable
BANK 0/DIMM0
4 GB DDR3 1600 MHz ok
BANK 1/DIMM0
4 GB DDR3 1600 MHz ok
Bluetooth: Good - Handoff/Airdrop2 supported
Wireless: en1: 802.11 a/b/g/n
Video Information: ℹ️
Intel HD Graphics 4000 -
Color LCD 1280 x 800
System Software: ℹ️
OS X 10.10 (14A389) - Uptime: 0:55:38
Disk Information: ℹ️
APPLE HDD TOSHIBA MK7559GSXF disk0 : (750.16 GB)
S.M.A.R.T. Status: Verified
EFI (disk0s1) <not mounted> : 210 MB
Recovery HD (disk0s3) <not mounted> [Recovery]: 650 MB
Macintosh HD (disk1) / [Startup]: 748.93 GB (574.29 GB free)
Encrypted AES-XTS UnlockedConverting
Core Storage: disk0s2 749.30 GB Online
MATSHITADVD-R UJ-8A8
USB Information: ℹ️
Apple Inc. FaceTime HD Camera (Built-in)
Apple Computer, Inc. IR Receiver
Apple Inc. Apple Internal Keyboard / Trackpad
Apple Inc. BRCM20702 Hub
Apple Inc. Bluetooth USB Host Controller
Thunderbolt Information: ℹ️
Apple Inc. thunderbolt_bus
Gatekeeper: ℹ️
Mac App Store and identified developers
Kernel Extensions: ℹ️
/System/Library/Extensions
[not loaded] com.leapfrog.codeless.kext (2) Support
[not loaded] com.leapfrog.driver.LfConnectDriver (1.9.8 - SDK 10.8) Support
[not loaded] com.sony.driver.dsccamFirmwareUpdaterType00 (1 - SDK 10.6) Support
Startup Items: ℹ️
ChmodBPF: Path: /Library/StartupItems/ChmodBPF
Startup items are obsolete and will not work in future versions of OS X
Problem System Launch Agents: ℹ️
[invalid?] com.VTech.AgentMonitor.plist Support
Launch Agents: ℹ️
[loaded] com.oracle.java.Java-Updater.plist Support
[running] com.sony.SonyAutoLauncher.agent.plist Support
[invalid?] com.support.com.peruser.Nexusd.plist Support
[invalid?] com.support.com.peruser.Nexussrvd.plist Support
Launch Daemons: ℹ️
[loaded] com.adobe.fpsaud.plist Support
[loaded] com.leapfrog.connect.authdaemon.plist Support
[loaded] com.macpaw.CleanMyMac2.Agent.plist Support
[loaded] com.oracle.java.Helper-Tool.plist Support
[loaded] com.oracle.java.JavaUpdateHelper.plist Support
User Launch Agents: ℹ️
[loaded] com.google.keystone.agent.plist Support
[running] com.leapfrog.connect.monitor.plist Support
[loaded] com.macpaw.CleanMyMac2Helper.diskSpaceWatcher.plist Support
[loaded] com.macpaw.CleanMyMac2Helper.scheduledScan.plist Support
[loaded] com.macpaw.CleanMyMac2Helper.trashWatcher.plist Support
[invalid?] com.support.com.peruser.Nexusd.plist Support
[invalid?] com.support.com.peruser.Nexussrvd.plist Support
User Login Items: ℹ️
iTunesHelper Application (/Applications/iTunes.app/Contents/MacOS/iTunesHelper.app)
Dropbox Application (/Applications/Dropbox.app)
Internet Plug-ins: ℹ️
SAFARIMontageInfo: Version: (null) - SDK 10.2 Support
FlashPlayer-10.6: Version: 15.0.0.152 - SDK 10.6 Support
QuickTime Plugin: Version: 7.7.3
Flash Player: Version: 15.0.0.152 - SDK 10.6 Mismatch! Adobe recommends 15.0.0.189
SAFARIMontageConnectPlugInNS: Version: (null) - SDK 10.2 Support
Default Browser: Version: 600 - SDK 10.10
SAFARIMontagePlayer: Version: (null) - SDK 10.8 Support
Silverlight: Version: 5.1.10411.0 - SDK 10.6 Support
JavaAppletPlugin: Version: Java 7 Update 67 Check version
User Internet Plug-ins: ℹ️
WebEx64: Version: 1.0 - SDK 10.6 Support
Google Earth Web Plug-in: Version: 7.1 Support
Safari Extensions: ℹ️
AdBlock
Add To Amazon Wish List
Open-Dyslexic (Disabled)
Print Plus
Evernote Web Clipper
iShorten
3rd Party Preference Panes: ℹ️
AppTrap Support
Flash Player Support
Java Support
Time Machine: ℹ️
Mobile backups: OFF
Auto backup: NO - Auto backup turned off
Destinations:
My Passport for Mac [Local]
Total size: 0 B
Total number of backups: 0
Oldest backup: -
Last backup: -
Size of backup disk: Excellent
Backup size 0 B > (Disk size 0 B X 3)
Top Processes by CPU: ℹ️
8% QuickLookSatellite
8% installer
7% WindowServer
4% Install Adobe Flash Player
3% com.hp.devicemonitor
Top Processes by Memory: ℹ️
155 MB softwareupdated
146 MB Finder
94 MB mds_stores
86 MB Dropbox
86 MB QuickLookSatellite
Virtual Memory Information: ℹ️
2.39 GB Free RAM
4.10 GB Active RAM
1.14 GB Inactive RAM
963 MB Wired RAM
1.91 GB Page-ins
0 B Page-outs -
After Effects Help | Improve performance
This question was posted in response to the following article: http://helpx.adobe.com/after-effects/using/improve-performance.html
The link to Cache Work Area in Background is wrong, it links to Memory instructions in CS5.5 and earlier instead of the CS6 feature that it should to.
-
I have this file but I need to improve the code on some method. The methods are addNode, deleteNode, saveNode, findLader and are they anyway for me to iliminate the findsmallest method?
here is the code
import java.io.*;
import java.util.LinkedList;
import java.util.Stack;
import javax.swing.*;
public class Graph {
private LinkedList graph;
private BufferedReader inputFile;
public Graph() {
graph = new LinkedList();
// read the words from the given file
// create a GraphNode
// Add the node to the graph
public void createGraph(String fileName) throws IOException {
inputFile = new BufferedReader(
new InputStreamReader(new FileInputStream("word.txt")));
// Convert the linkedlist to an array 'a'
// sort the array 'a'
// create a string from all elements in 'a'
// return the string
public String printGraph() {
String output = new String();
// will contain String objects
// ... do some work with the list, adding, removing String objects
String[] a = new String[graph.size()];
graph.toArray(a);
// now stringArray contains all the element from linkedList
quickSort(a, 0, a.size() - 1);
for(int i=0;i<a.length;++i)
output = output + new String(a.toString())+"\n";
return output;
private static void quickSort(Comparable[] theArray,
int first, int last) {
// Sorts the items in an array into ascending order.
// Precondition: theArray[first..last] is an array.
// Postcondition: theArray[first..last] is sorted.
// Calls: partition.
int pivotIndex;
if (first < last) {
// create the partition: S1, Pivot, S2
pivotIndex = partition(theArray, first, last);
// sort regions S1 and S2
quickSort(theArray, first, pivotIndex-1);
quickSort(theArray, pivotIndex+1, last);
} // end if
} // end quickSort
private static int partition(Comparable[] theArray,
int first, int last) {
// Partitions an array for quicksort.
// Precondition: theArray[first..last] is an array;
// first <= last.
// Postcondition: Returns the index of the pivot element of
// theArray[first..last]. Upon completion of the method,
// this will be the index value lastS1 such that
// S1 = theArray[first..lastS1-1] < pivot
// theArray[lastS1] == pivot
// S2 = theArray[lastS1+1..last] >= pivot
// Calls: choosePivot.
// tempItem is used to swap elements in the array
Comparable tempItem;
// place pivot in theArray[first]
//choosePivot(theArray, first, last);
Comparable pivot = theArray[first]; // reference pivot
// initially, everything but pivot is in unknown
int lastS1 = first; // index of last item in S1
// move one item at a time until unknown region is empty
for (int firstUnknown = first + 1; firstUnknown <= last;
++firstUnknown) {
// Invariant: theArray[first+1..lastS1] < pivot
// theArray[lastS1+1..firstUnknown-1] >= pivot
// move item from unknown to proper region
if (theArray[firstUnknown].compareTo(pivot) < 0) {
// item from unknown belongs in S1
++lastS1;
tempItem = theArray[firstUnknown];
theArray[firstUnknown] = theArray[lastS1];
theArray[lastS1] = tempItem;
} // end if
// else item from unknown belongs in S2
} // end for
// place pivot in proper position and mark its location
tempItem = theArray[first];
theArray[first] = theArray[lastS1];
theArray[lastS1] = tempItem;
return lastS1;
} // end partition
// Given a new word, add it to the graph
public void addNode(String word) {
GraphNode node = new GraphNode(word);
if(graph.contains(node)){
JOptionPane.showMessageDialog(null,"Duplicate Word, operation terminated");
for(int i=0; i<graph.size(); ++i) {
if(isAnEdge((String)(((GraphNode)graph.get(i)).getVertex()),(String)(node.getVertex()))) {
EdgeNode e1 = new EdgeNode((String)node.getVertex(),1);
EdgeNode e2 = new EdgeNode((String)((GraphNode)graph.get(i)).getVertex(),1);
node.addEdge(e2);
((GraphNode)graph.get(i)).addEdge(e1);
graph.add(node);
public boolean deleteNode(String word) {
GraphNode node = new GraphNode(word);
EdgeNode n = new EdgeNode(word,1);
if(!graph.contains(node)) {
return false;
else {
for(int i=0; i<graph.size();++i) {
((GraphNode)graph.get(i)).getEdgeList().remove(n);
graph.remove(node);
return true;
public void save(String fileName) {
try {
PrintWriter output = new PrintWriter(new FileWriter("word.txt"));
for(int i=0; i< graph.size();++i) {
output.println(((GraphNode)graph.get(i)).getVertex());
output.close();
catch (IOException e) {
// given two word, find the ladder (using dijkstra's algorithm
// create a string for the ladder and return it
public String findLadder(String start,String end) {
String ladder = new String();
GraphNode sv = new GraphNode(start);
GraphNode ev = new GraphNode(end);
if(!graph.contains(sv)) {
JOptionPane.showMessageDialog(null,start + " not in graph");
return null;
if(!graph.contains(ev)) {
JOptionPane.showMessageDialog(null,end + " not in graph");
return null;
LinkedList distance = new LinkedList(((GraphNode)graph.get(graph.indexOf(sv))).getEdgeList());
LinkedList visited = new LinkedList();
visited.add(start);
LinkedList path = new LinkedList();
path.add(new PathNode(start,"****"));
for(int i=0; i<distance.size();++i) {
PathNode p = new PathNode((String)((EdgeNode)distance.get(i)).getKey(),start);
path.add(p);
while(!visited.contains(end)) {
EdgeNode min = findSmallest(distance,visited);
String v = (String)min.getVertex();
if(v.equals("****"))
return null;
visited.add(v);
// for(int i=0;i<graph.size();++i) {
// String u = (String)(((GraphNode)(graph.get(i))).getVertex());
GraphNode temp1 = new GraphNode(v);
int index = graph.indexOf(temp1);
LinkedList l = new LinkedList(((GraphNode)graph.get(index)).getEdgeList());
for(int i=0;i<l.size();++i)
String u = (String)(((EdgeNode)(l.get(i))).getVertex());
if(!visited.contains(u)) {
int du=999, dv=999, avu=999;
dv = min.getCost();
EdgeNode edge = new EdgeNode(u,1);
if(distance.contains(edge)) {
du = ((EdgeNode)(distance.get(distance.indexOf(edge)))).getCost();
GraphNode temp = new GraphNode(v);
GraphNode node = ((GraphNode)(graph.get(graph.indexOf(temp))));
LinkedList edges = node.getEdgeList();
if(edges.contains(edge)) {
avu = ((EdgeNode)(edges.get(edges.indexOf(new EdgeNode(u,1))))).getCost();
if( du > dv+avu) {
if(du == 999) {
distance.add(new EdgeNode(u,dv+avu));
path.add(new PathNode(u,v));
else {
((EdgeNode)(distance.get(distance.indexOf(u)))).setCost(dv+avu);
((PathNode)(path.get(path.indexOf(u)))).setEnd(v);
if(!path.contains(new PathNode(end,"")))
return null;
LinkedList pathList = new LinkedList();
for(int i=0;i<path.size();++i) {
PathNode n = (PathNode)path.get(path.indexOf(new PathNode(end,"****")));
if(n.getEnd().compareTo("****") != 0) {
pathList.addFirst(end);
n = (PathNode)path.get(path.indexOf(new PathNode(n.getEnd(),"****")));
end = n.getStart();
pathList.addFirst(start);
for(int i=0;i<pathList.size()-1;++i) {
ladder = ladder + ((String)(pathList.get(i))) + " --> ";
ladder = ladder + ((String)(pathList.get(pathList.size()-1)));
return ladder;
private EdgeNode findSmallest(LinkedList distance, LinkedList visited) {
EdgeNode min = new EdgeNode("****",999);
for(int i=0;i<distance.size();++i) {
String node = (String)(((EdgeNode)distance.get(i)).getVertex());
if(!visited.contains(node)) {
if(((EdgeNode)distance.get(i)).getCost()<min.getCost()) {
min = (EdgeNode)distance.get(i);
return min;
// class that represents nodes inserted into path set
private class PathNode {
protected String sv;
protected String ev;
public PathNode(String s,String e) {
sv = s;
ev = e;
public String getEnd() {
return ev;
public String getStart() {
return sv;
public void setEnd(String n) {
ev = n;
public boolean equals(Object o) {
return this.sv.equals(((PathNode)o).sv);
public String toString() {
return "("+sv+":"+ev+")";
thank youlet me fix my misstake which was point out by some one in here and thank you ofr do so because I'm new at this.
I have this file but I need to improve the code on some method. The methods are addNode, deleteNode, saveNode, findLader and are they anyway for me to iliminate the findsmallest method?
here is the code
import java.io.*;
import java.util.LinkedList;
import java.util.Stack;
import javax.swing.*;
public class Graph {
private LinkedList graph;
private BufferedReader inputFile;
public Graph() {
graph = new LinkedList();
// read the words from the given file
// create a GraphNode
// Add the node to the graph
public void createGraph(String fileName) throws IOException {
inputFile = new BufferedReader(
new InputStreamReader(new FileInputStream("word.txt")));
// Convert the linkedlist to an array 'a'
// sort the array 'a'
// create a string from all elements in 'a'
// return the string
public String printGraph() {
String output = new String();
// will contain String objects
// ... do some work with the list, adding, removing String objects
String[] a = new String[graph.size()];
graph.toArray(a);
// now stringArray contains all the element from linkedList
quickSort(a, 0, a.size() - 1);
for(int i=0;i<a.length;++i)
output = output + new String(a.toString())+"\n";
return output;
private static void quickSort(Comparable[] theArray,
int first, int last) {
// Sorts the items in an array into ascending order.
// Precondition: theArray[first..last] is an array.
// Postcondition: theArray[first..last] is sorted.
// Calls: partition.
int pivotIndex;
if (first < last) {
// create the partition: S1, Pivot, S2
pivotIndex = partition(theArray, first, last);
// sort regions S1 and S2
quickSort(theArray, first, pivotIndex-1);
quickSort(theArray, pivotIndex+1, last);
} // end if
} // end quickSort
private static int partition(Comparable[] theArray,
int first, int last) {
// Partitions an array for quicksort.
// Precondition: theArray[first..last] is an array;
// first <= last.
// Postcondition: Returns the index of the pivot element of
// theArray[first..last]. Upon completion of the method,
// this will be the index value lastS1 such that
// S1 = theArray[first..lastS1-1] < pivot
// theArray[lastS1] == pivot
// S2 = theArray[lastS1+1..last] >= pivot
// Calls: choosePivot.
// tempItem is used to swap elements in the array
Comparable tempItem;
// place pivot in theArray[first]
//choosePivot(theArray, first, last);
Comparable pivot = theArray[first]; // reference pivot
// initially, everything but pivot is in unknown
int lastS1 = first; // index of last item in S1
// move one item at a time until unknown region is empty
for (int firstUnknown = first + 1; firstUnknown <= last;
++firstUnknown) {
// Invariant: theArray[first+1..lastS1] < pivot
// theArray[lastS1+1..firstUnknown-1] >= pivot
// move item from unknown to proper region
if (theArray[firstUnknown].compareTo(pivot) < 0) {
// item from unknown belongs in S1
++lastS1;
tempItem = theArray[firstUnknown];
theArray[firstUnknown] = theArray[lastS1];
theArray[lastS1] = tempItem;
} // end if
// else item from unknown belongs in S2
} // end for
// place pivot in proper position and mark its location
tempItem = theArray[first];
theArray[first] = theArray[lastS1];
theArray[lastS1] = tempItem;
return lastS1;
} // end partition
// Given a new word, add it to the graph
public void addNode(String word) {
GraphNode node = new GraphNode(word);
if(graph.contains(node)){
JOptionPane.showMessageDialog(null,"Duplicate Word, operation terminated");
for(int i=0; i<graph.size(); ++i) {
if(isAnEdge((String)(((GraphNode)graph.get(i)).getVertex()),(String)(node.getVertex()))) {
EdgeNode e1 = new EdgeNode((String)node.getVertex(),1);
EdgeNode e2 = new EdgeNode((String)((GraphNode)graph.get(i)).getVertex(),1);
node.addEdge(e2);
((GraphNode)graph.get(i)).addEdge(e1);
graph.add(node);
public boolean deleteNode(String word) {
GraphNode node = new GraphNode(word);
EdgeNode n = new EdgeNode(word,1);
if(!graph.contains(node)) {
return false;
else {
for(int i=0; i<graph.size();++i) {
((GraphNode)graph.get(i)).getEdgeList().remove(n);
graph.remove(node);
return true;
public void save(String fileName) {
try {
PrintWriter output = new PrintWriter(new FileWriter("word.txt"));
for(int i=0; i< graph.size();++i) {
output.println(((GraphNode)graph.get(i)).getVertex());
output.close();
catch (IOException e) {
// given two word, find the ladder (using dijkstra's algorithm
// create a string for the ladder and return it
public String findLadder(String start,String end) {
String ladder = new String();
GraphNode sv = new GraphNode(start);
GraphNode ev = new GraphNode(end);
if(!graph.contains(sv)) {
JOptionPane.showMessageDialog(null,start + " not in graph");
return null;
if(!graph.contains(ev)) {
JOptionPane.showMessageDialog(null,end + " not in graph");
return null;
LinkedList distance = new LinkedList(((GraphNode)graph.get(graph.indexOf(sv))).getEdgeList());
LinkedList visited = new LinkedList();
visited.add(start);
LinkedList path = new LinkedList();
path.add(new PathNode(start,"****"));
for(int i=0; i<distance.size();++i) {
PathNode p = new PathNode((String)((EdgeNode)distance.get(i)).getKey(),start);
path.add(p);
while(!visited.contains(end)) {
EdgeNode min = findSmallest(distance,visited);
String v = (String)min.getVertex();
if(v.equals("****"))
return null;
visited.add(v);
// for(int i=0;i<graph.size();++i) {
// String u = (String)(((GraphNode)(graph.get(i))).getVertex());
GraphNode temp1 = new GraphNode(v);
int index = graph.indexOf(temp1);
LinkedList l = new LinkedList(((GraphNode)graph.get(index)).getEdgeList());
for(int i=0;i<l.size();++i)
String u = (String)(((EdgeNode)(l.get(i))).getVertex());
if(!visited.contains(u)) {
int du=999, dv=999, avu=999;
dv = min.getCost();
EdgeNode edge = new EdgeNode(u,1);
if(distance.contains(edge)) {
du = ((EdgeNode)(distance.get(distance.indexOf(edge)))).getCost();
GraphNode temp = new GraphNode(v);
GraphNode node = ((GraphNode)(graph.get(graph.indexOf(temp))));
LinkedList edges = node.getEdgeList();
if(edges.contains(edge)) {
avu = ((EdgeNode)(edges.get(edges.indexOf(new EdgeNode(u,1))))).getCost();
if( du > dv+avu) {
if(du == 999) {
distance.add(new EdgeNode(u,dv+avu));
path.add(new PathNode(u,v));
else {
((EdgeNode)(distance.get(distance.indexOf(u)))).setCost(dv+avu);
((PathNode)(path.get(path.indexOf(u)))).setEnd(v);
if(!path.contains(new PathNode(end,"")))
return null;
LinkedList pathList = new LinkedList();
for(int i=0;i<path.size();++i) {
PathNode n = (PathNode)path.get(path.indexOf(new PathNode(end,"****")));
if(n.getEnd().compareTo("****") != 0) {
pathList.addFirst(end);
n = (PathNode)path.get(path.indexOf(new PathNode(n.getEnd(),"****")));
end = n.getStart();
pathList.addFirst(start);
for(int i=0;i<pathList.size()-1;++i) {
ladder = ladder + ((String)(pathList.get(i))) + " --> ";
ladder = ladder + ((String)(pathList.get(pathList.size()-1)));
return ladder;
private EdgeNode findSmallest(LinkedList distance, LinkedList visited) {
EdgeNode min = new EdgeNode("****",999);
for(int i=0;i<distance.size();++i) {
String node = (String)(((EdgeNode)distance.get(i)).getVertex());
if(!visited.contains(node)) {
if(((EdgeNode)distance.get(i)).getCost()<min.getCost()) {
min = (EdgeNode)distance.get(i);
return min;
// class that represents nodes inserted into path set
private class PathNode {
protected String sv;
protected String ev;
public PathNode(String s,String e) {
sv = s;
ev = e;
public String getEnd() {
return ev;
public String getStart() {
return sv;
public void setEnd(String n) {
ev = n;
public boolean equals(Object o) {
return this.sv.equals(((PathNode)o).sv);
public String toString() {
return "("+sv+":"+ev+")";
}thank you -
Need help on performing database queries with a general query
Dear experts,
I have two issues
1)
I have developed a software which connects to Oracle database
performing and executing DDL/DML statements.
I am using a Jdbc thin oracle driver.
When i perform a wrong syntax query or say a query using invalid column.I get exception accordingly.However,I want to know if there is any way by which i can know the exact position where i am making error
just as an asterik(*) comes in sql plus in case of invalid column or so.
2)
Whenever i minimize software window (made of swing components)
and again maximize it.It takes almost 12 secs to be visible otherwise it remains white.Is swing that much slow ???(1) No.
(2) It's possible to make Swing programs that slow. (I know, I have done it.) But usually the slowness is in application code (your code) and not in Swing itself. -
Need help improving XP SP3 performance on 4-core Mac Pro 2009
I'm running Windows XP SP3 under Boot Camp 3 (Mac OS X v. 10.6.2). Currently, XP is on a second partitioned HD, but it was previously running on a drive all its own with the same problems which are:
When I boot into Windows the sound stutters quite a bit. I updated the Realtek drivers and used the Apple USB device (24" LED speakers) but nothing completely got rid of the static/stuttering.
The real problem comes when running Left 4 Dead. Whenever I get to a new part of any level (where zombies are) the graphics freeze for up to a few seconds and the sound gets glitchy, repeating broken staticky snippets. I don't have other games installed but I get similar performance when watching a YouTube video in Firefox.
Is this normal for Windows on a Mac Pro or do other Mac Pro Boot Campers run Windows smoothly? I have seen YouTube videos of Windows running smoothly on MacBook Pros and iMacs. Just wondering if I'm doing something wrong.
Finally, I'm running two graphics cards, an ATI 4870 and an NVIDIA GT120. I've run with both on, one off, the other off, the NVIDIA removed, the NVIDIA installed. No matter what I do, the video glitchiness is always pretty bad. (The audio is also bad.)
Thanks in advance for any info or pointers.I have had success running boot camp on an 8-core Mac Pro from 2009. I have an ATI 4870.
I initially used Windows 7 Beta (32bit) and then RC (64bit) and finally the shipping version (64 bit Professional).
32-Bit crippled Crysis performance for me (only the demo). I was able to run the game with most settings all the way up (excluding Anti-aliasing), at 1920x1080 and it ran fine for about one minute before hitting the hard-drive for about 10 seconds. This thrashing occurred repeatedly and I have up - that problem was resolved when I moved to 64bit Windows.
Other games I have played with no trouble are The Orange Box & Borderlands, each with maxed resolution and settings.
Optical audio and the front headphones work fine for me - though the 4 conductor cord does not recognize the microphone (from an iPhone headset) in Windows, which gets me down as it would be nice to audio-chat in some games.
Try these thing in this order if you can, and have not already:
Patch the game (though if this is happening in Firefox as well, it seems like an OS problem)
Update directX (I really have no clue here, I assume Windows does this automatically?)
Try demos of other games
Upgrade the OS to 64bit (Especially if you have over 3GB of ram
Go from XP to 7 (I have had no trouble with Windows 7 on my machine)
Try a DVI monitor (I am using a 21" Westinghouse, have never connected an Apple display)
Good luck!
Owen -
Need to improve performance of oracle query
Hi ,
Currently i have written query to get maximun salary from XYZ company like this
select salary from (
select salary from employee
where company='XYZ'
order by salary desc )
where rownum<2;
i thought of replacing the same with following query
select max(salary)
from employee
where company='XYZ';
Which one will be faster ? can you provide some statistical data.It will be good if you share some oracle documentation for this.
Thanks,
KannanMost likely the second one. And in any case: the second one is much more straightforward and readable (i.e. the syntax describes exactly what you want: get the max salary). In that way, your application is better maintainable (i.e. cheaper and better in the long run), and likely more easy to optimize for the database. And yes, in this case it's a simple query, but if you're thinking of writing even simple queries in the style of your first example, I'd hate to think of what more complex queries would get to look like...
-
Need to Improve Performance on a Spatial Boundary Crossing Calculator
I am attempting to compare a series of geometries to calculate a number of statistics where they overlap. Essentially I have a table of 50,000 lines and another table of 1000 circles. I need to determine which lines overlap each circle, and for each intersection, I need to determine how much time and distance each line spends in each circle.
I have a PL/SQL program that performs this operation now and it works. The problem is that it takes far too long.
Here is a summary of how the job runs:
1) For each LINE, determine which CIRCLES it overlaps with
2) Each each LINE/CIRCLE pair, determine the intersection points
3) Insert the intersection points in a temporary table
4) Once you have all the points, pair them up as Entry/Exit points for each circle
5) Calculate duration (time) and distance between entry and exit points
6) Return to step 1 for next LINE
There are multiple loops here:
1-6 is the outer loop performed once for each of the 50,000 lines.
2-3 is performed once for each line/circle pair (probable avg of 5 circles per line)
4-5 is performed once again for each line/circle pair
Even if the process only takes a couple of seconds per LINE, we are still taking more than 24 hours to process, which is not acceptable.
This original process was written with 9i, and I am now running 10gR2, so I know there are new features that should help. For starters, I think I can use SDO_JOIN in place of the original outer loop to generate a complete list of geometry interactions in one query. Of course, I am still concerned about how long that might take.
Even more troubling is, if that works, I still don't see how to improve the rest of the calculations. Any suggestions would be appreciated.No, I don't mind providing it.
Here it is:
-- cre_&stab._bndxing.sql
--Procedure definition of bndxings
def stab=&1
CREATE OR REPLACE PROCEDURE Find_&stab._bndxings
(theDate IN DATE, theStr IN VARCHAR2) IS
--Select flights from table
CURSOR FCursor IS
SELECT new_Flight_Index,
Acid,
New_Act_Date,
Dept_Aprt,
Dep_Time,
Arr_Aprt,
Arr_Time,
Acft_Type,
Physical_Class,
User_Class,
Nrp,
d_lat,
d_lon,
a_lat,
a_lon,
flight_track
FROM jady.Flight
WHERE new_act_date = theDate
AND flight_track IS NOT NULL
AND substr(acid,1,1) = theStr
--AND acid in (select acid from name_temp)
--AND acid = 'AAL1242'
ORDER BY acid,new_flight_index;
--Temp vars for storing flight info
fi_var NUMBER;
acid_var VARCHAR2(7);
dep_time_var DATE;
arr_time_var DATE;
F_Rec FCursor%ROWTYPE;
--Temp vars for flight
tcnt INTEGER;
cur_lat NUMBER;
cur_lon NUMBER;
last_lat NUMBER;
last_lon NUMBER;
--Temp vars for airspace and xing geometries
aname VARCHAR2(20);
bxings MDSYS.SDO_GEOMETRY;
bxcnt INTEGER;
--Select xings made from temp bndxing table
CURSOR XCursor IS
SELECT Act_Date,
Name,
Lon,
Lat,
Alt,
Time,
OPS
FROM bndxing_tmp
WHERE Flight_Index = fi_var
AND Acid = acid_var
ORDER BY Name,Time;
--Temp vars for paired in/out xings
ad date;
ilon NUMBER;
ilat NUMBER;
ialt NUMBER;
isec NUMBER;
iops NUMBER;
olon NUMBER;
olat NUMBER;
oalt NUMBER;
osec NUMBER;
oops NUMBER;
gcr NUMBER;
dist NUMBER;
dura NUMBER;
ops VARCHAR2(1);
i INTEGER;
i_aname VARCHAR2(20);
o_aname VARCHAR2(20);
names_match BOOLEAN;
theSeq NUMBER;
same_airport_no_tzdata BOOLEAN;
-- Cursor and variables for bndxing sequencing
CURSOR BCursor IS
SELECT * FROM bndxing
WHERE act_date = theDate
AND Acid = acid_var
AND Flight_Index = fi_var
ORDER BY in_time
FOR UPDATE;
BRec BCursor%ROWTYPE;
--Error logging variable
strErrorMessage VARCHAR2(255);
BEGIN --Start of Main Loop
--Loop for each flight in table
OPEN FCursor;
FETCH FCursor INTO F_Rec;
-- FOR f IN FCursor LOOP
WHILE FCursor%FOUND LOOP
fi_var:= F_Rec.new_Flight_Index;
acid_var := F_Rec.acid;
arr_time_var := F_Rec.arr_time;
dep_time_var := F_Rec.dep_time;
last_lat := -10000; --initializtion
last_lon := -10000; --initializtion
-- DEBUG STATEMENT
/* Insert into bnd_error values (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Checkpoint 1');
--Add departing xing to temp table if in US airspace
DECLARE
CURSOR DepCur IS
SELECT Name
FROM &stab.
WHERE SDO_RELATE(Airspace,
MDSYS.SDO_GEOMETRY(2001,8307,
MDSYS.SDO_POINT_TYPE(F_Rec.d_lon,F_Rec.d_lat,null),
null, null),
'mask=CONTAINS querytype=WINDOW') = 'TRUE';
BEGIN -- Start of Departing Airspace Loop
FOR c in DepCur LOOP
INSERT INTO Bndxing_Tmp VALUES (F_Rec.new_Flight_Index,
F_Rec.acid,
F_Rec.New_Act_Date,
c.name,
2,
F_Rec.d_lon,
F_Rec.d_lat,
0,
(F_Rec.Dep_Time-F_Rec.New_Act_Date)*86400);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
WHEN OTHERS THEN
strErrorMessage := SQLERRM;
INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Exception from Departing Airspace loop: ' || strErrorMessage);
COMMIT;
END; -- End of Departing Airspace Loop
--Add arrival xing to temp table if in US airspace
DECLARE
CURSOR ArrCur IS
SELECT name
FROM &stab.
WHERE SDO_RELATE(Airspace,
MDSYS.SDO_GEOMETRY(2001,8307,
MDSYS.SDO_POINT_TYPE(F_Rec.a_lon, F_Rec.a_lat, null),
null, null),
'mask=CONTAINS querytype=WINDOW') = 'TRUE';
BEGIN -- Start of Arrival Airspace Loop
FOR c IN ArrCur LOOP
INSERT INTO Bndxing_Tmp VALUES (F_Rec.new_Flight_Index,
F_Rec.acid,
F_Rec.New_Act_Date,
c.name,
1,
F_Rec.a_lon,
F_Rec.a_lat,
0,
(F_Rec.Arr_Time - F_Rec.New_Act_Date)*86400);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
WHEN OTHERS THEN
strErrorMessage := SQLERRM;
INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Exception from Arrival Airspace loop: ' || strErrorMessage);
COMMIT;
END; -- End of Arrival Airspace Loop
--DEBUG STATEMENT
/* Insert into bnd_error values (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Checkpoint 4');
--Find all intersections between the flight track and airspace boundaries and insert into temp table
DECLARE
--Find airspace boundaries that interact with the flight track
CURSOR CCursor IS
SELECT Name, Boundary
FROM &stab.
WHERE SDO_RELATE(boundary,F_Rec.flight_track,'mask=OVERLAPBDYDISJOINT querytype=WINDOW')='TRUE';
BEGIN
FOR c IN CCursor LOOP
bxings := SDO_GEOM.SDO_INTERSECTION(c.boundary,F_Rec.flight_track,10);
bxcnt:=bxings.sdo_ordinates.count;
LOOP
INSERT INTO bndxing_tmp VALUES (F_Rec.new_Flight_Index,
F_Rec.acid,
F_Rec.New_Act_Date,
c.name,
0,
bxings.sdo_ordinates(bxcnt-3),
bxings.sdo_ordinates(bxcnt-2),
bxings.sdo_ordinates(bxcnt-1),
SDO_LRS.FIND_MEASURE(F_Rec.flight_track,
MDSYS.SDO_GEOMETRY(2001,8307,NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),
MDSYS.SDO_ORDINATE_ARRAY(bxings.sdo_ordinates(bxcnt-3),
bxings.sdo_ordinates(bxcnt-2)))));
bxcnt := bxcnt - 4;
EXIT WHEN (bxcnt < 1);
END LOOP;
END LOOP; -- end CCursor LOOP
EXCEPTION
WHEN OTHERS THEN
strErrorMessage := SQLERRM;
INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Exception from bndxing loop: ' || strErrorMessage);
COMMIT;
END;
--DEBUG STATEMENT
/* Insert into bnd_error values (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Checkpoint 6');
--After all xings for a flight have been collected sort Xings by name and time and grab pairwise
theSeq :=0;
OPEN XCursor;
BEGIN -- Start of Stats Loop
LOOP
FETCH XCursor INTO ad, i_aname, ilon, ilat, ialt, isec, iops; --CHANGED CODE
EXIT WHEN XCursor%NOTFOUND ;
FETCH XCursor INTO ad, o_aname, olon, olat, oalt, osec, oops; --CHANGED CODE
EXIT WHEN XCursor%NOTFOUND ;
names_match := (i_aname = o_aname); --NEW CODE
WHILE not names_match LOOP --NEW CODE
i_aname := o_aname; --NEW CODE
ilon := olon; --NEW CODE
ilat := olat; --NEW CODE
ialt := oalt; --NEW CODE
isec := osec; --NEW CODE
iops := oops; --NEW CODE
FETCH XCursor INTO ad, o_aname, olon, olat, oalt, osec, oops; --NEW CODE
EXIT WHEN XCursor%NOTFOUND; --NEW CODE
names_match := (i_aname = o_aname); --NEW CODE
END LOOP; --NEW CODE
--Calculate stats
BEGIN -- Start of In Values Loop
i:=4;
IF (iops<>2) THEN
-- Did not depart from this airspace, calculate entry altitude into airspace.
LOOP
i:=i+4;
EXIT WHEN F_Rec.flight_track.sdo_ordinates(i)>isec;
END LOOP;
IF ( F_Rec.flight_track.sdo_ordinates(i-1) = F_Rec.flight_track.sdo_ordinates(i-5) ) THEN
ialt := F_Rec.flight_track.sdo_ordinates(i-1);
ELSE
ialt:=SDO_LRS.FIND_MEASURE(
MDSYS.SDO_GEOMETRY(3302,8307,NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),
MDSYS.SDO_ORDINATE_ARRAY(F_Rec.flight_track.sdo_ordinates(i-7),
F_Rec.flight_track.sdo_ordinates(i-6),
F_Rec.flight_tracK.sdo_ordinates(i-5),
F_Rec.flight_track.sdo_ordinates(i-3),
F_Rec.flight_track.sdo_ordinates(i-2),
F_Rec.flight_track.sdo_ordinates(i-1))),
MDSYS.SDO_GEOMETRY(2001,8307,NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),
MDSYS.SDO_ORDINATE_ARRAY(ilon,ilat)));
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
strErrorMessage := SQLERRM;
INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Exception from In Values section: ' || strErrorMessage);
COMMIT;
END; -- End of In Values Loop
BEGIN -- Start of Out Values Loop
i:=4;
IF (oops<>1) THEN
-- Did not arrive in this airspace, calculate departure altitude from airspace.
LOOP
i:=i+4;
EXIT WHEN F_Rec.flight_track.sdo_ordinates(i)>osec;
END LOOP;
--Find alt at this time
IF ( F_Rec.flight_track.sdo_ordinates(i-1) = F_Rec.flight_track.sdo_ordinates(i-5) ) THEN
oalt := F_Rec.flight_track.sdo_ordinates(i-1);
ELSE
oalt:=SDO_LRS.FIND_MEASURE(
MDSYS.SDO_GEOMETRY(3302, 8307, NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),
MDSYS.SDO_ORDINATE_ARRAY(F_Rec.flight_track.sdo_ordinates(i-7),
F_Rec.flight_track.sdo_ordinates(i-6),
F_Rec.flight_track.sdo_ordinates(i-5),
F_Rec.flight_track.sdo_ordinates(i-3),
F_Rec.flight_track.sdo_ordinates(i-2),
F_Rec.flight_track.sdo_ordinates(i-1))),
MDSYS.SDO_GEOMETRY(2001,8307,NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),
MDSYS.SDO_ORDINATE_ARRAY(olon,olat)));
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
strErrorMessage := SQLERRM;
INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Exception from Out Values loop: ' || strErrorMessage);
COMMIT;
END; -- End of Out Values Loop
BEGIN -- Start of Finish Loop
--Find GCR, actual distance and duration in airspace
gcr := SDO_GEOM.SDO_DISTANCE(MDSYS.SDO_GEOMETRY(2001,8307,
MDSYS.SDO_POINT_TYPE(ilon,ilat,NULL),NULL,NULL),
MDSYS.SDO_GEOMETRY(2001,8307,
MDSYS.SDO_POINT_TYPE(olon,olat,NULL),NULL,NULL),
10,'unit=naut_mile');
--DEBUG STATEMENT
/* Insert into bnd_error values (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'In Finish Loop: isec: ' ||isec||' osec: '||osec
||' airspace: '||i_aname);
dist := SDO_GEOM.SDO_LENGTH(SDO_LRS.CLIP_GEOM_SEGMENT(F_Rec.flight_track,isec,osec),10,'unit=naut_mile');
dura := (osec - isec);
--Set OPS Flag
iops := iops + oops;
IF (iops=3) THEN
ops := 'B';
ELSIF (iops=2) THEN
ops := 'D';
ELSIF (iops=1) THEN
ops := 'A';
ELSE
ops := 'O';
END IF;
theSeq := theSeq + 1;
--Insert into Bndxing table
INSERT INTO Bndxing VALUES (F_Rec.Acid,
F_Rec.new_Flight_Index,
F_Rec.New_Act_Date,
theSeq,
F_Rec.Dept_Aprt,
F_Rec.Arr_Aprt,
i_aname,
round(ilon,3),
round(ilat,3),
ialt,
isec/86400 + ad,
NULL, -- IN_SPEED (TBD)
round(olon,3),
round(olat,3),
oalt,
osec/86400 + ad,
NULL, -- OUT_SPEED (TBD)
gcr,
dist,
dura,
ops, -- CHANGED CODE
nvl(F_Rec.Acft_Type,'----'),
NULL, -- IF_FLAG (NULL)
nvl(F_Rec.Physical_Class,'-'),
nvl(F_Rec.User_Class,'-'),
F_Rec.Nrp,
NULL, -- FFS_FLAG (NULL)
NULL, -- ER_SG (NULL)
NULL, -- ER_TI (NULL)
NULL, -- ER_ZT (NULL)
NULL, -- ER_DU (NULL)
NULL, -- ER_SP (NULL)
NULL -- ER_BD (NULL)
DELETE FROM bndxing_tmp
WHERE acid=F_Rec.Acid and flight_index=F_Rec.new_Flight_Index;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
strErrorMessage := SQLERRM;
INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Exception from Finish loop: ' || strErrorMessage);
COMMIT;
END; -- End of Finish Loop
END LOOP;
EXCEPTION
WHEN OTHERS THEN
strErrorMessage := SQLERRM;
INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
sysdate,
F_Rec.Acid,
F_Rec.new_Flight_Index,
'Exception from Stats loop: ' || strErrorMessage);
COMMIT;
END; -- End of Stats Loop
--Reset cursor and track geometry
CLOSE XCursor;
F_Rec.flight_track.sdo_ordinates.delete;
-- delete from hist_bndxing_tmp
-- where acid=acid_var and new_flight_index=fi_var;
FETCH FCursor INTO F_Rec;
END LOOP;
--DEBUG STATEMENT
/* INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
sysdate,
acid_var,
fi_var,
'Checkpoint 7');
CLOSE FCursor;
theSeq := 1;
OPEN BCursor;
LOOP
FETCH BCursor INTO BRec;
IF BCursor%NOTFOUND THEN
EXIT;
END IF;
UPDATE bndxing
SET segment = theSeq
WHERE CURRENT OF BCursor;
theSeq := theSeq + 1;
END LOOP;
CLOSE BCursor;
EXCEPTION
WHEN OTHERS THEN
strErrorMessage := SQLERRM;
Insert into bnd_error values (err_seq.NEXTVAL,
sysdate,
acid_var,
fi_var,
'Exception from main: ' || strErrorMessage);
COMMIT;
CLOSE FCursor;
END; -- End of Main Loop
SHOW ERRORS;
--exit; -
hallow
i doing this select and it take more then 10 minutes and i don't now way because
object_key have just 60 entries ?
how i can slve this problem?
Regards
SELECT * FROM covp APPENDING TABLE *covp
FOR ALL ENTRIES IN object_key
WHERE kokrs EQ '1000'
AND objnr EQ object_key-objnr
AND budat IN so_budat
AND stflg EQ space .Ways of Performance Tuning
1. Selection Criteria
2. Select Statements
Select Queries
SQL Interface
Aggregate Functions
For all Entries
Select Over more than one internal table
Selection Criteria
1. Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement.
2. Select with selection list.
SELECT * FROM SBOOK INTO SBOOK_WA.
CHECK: SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
ENDSELECT.
The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list
SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
WHERE SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
Select Statements Select Queries
1. Avoid nested selects
SELECT * FROM EKKO INTO EKKO_WA.
SELECT * FROM EKAN INTO EKAN_WA
WHERE EBELN = EKKO_WA-EBELN.
ENDSELECT.
ENDSELECT.
The above code can be much more optimized by the code written below.
SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
FROM EKKO AS P INNER JOIN EKAN AS F
ON PEBELN = FEBELN.
Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.
2. Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
SELECT * FROM SBOOK INTO SBOOK_WA.
CHECK: SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
ENDSELECT.
The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table
SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
WHERE SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
3. When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields. In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.
4. For testing existence, use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit.
SELECT * FROM SBOOK INTO SBOOK_WA
UP TO 1 ROWS
WHERE CARRID = 'LH'.
ENDSELECT.
The above code is more optimized as compared to the code mentioned below for testing existence of a record.
SELECT * FROM SBOOK INTO SBOOK_WA
WHERE CARRID = 'LH'.
EXIT.
ENDSELECT.
5. Use Select Single if all primary key fields are supplied in the Where condition .
If all primary key fields are supplied in the Where conditions you can even use Select Single.
Select Single requires one communication with the database system, whereas Select-Endselect needs two.
Select Statements SQL Interface
1. Use column updates instead of single-row updates
to update your database tables.
SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
SFLIGHT_WA-SEATSOCC =
SFLIGHT_WA-SEATSOCC - 1.
UPDATE SFLIGHT FROM SFLIGHT_WA.
ENDSELECT.
The above mentioned code can be more optimized by using the following code
UPDATE SFLIGHT
SET SEATSOCC = SEATSOCC - 1.
2. For all frequently used Select statements, try to use an index.
SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
WHERE CARRID = 'LH'
AND CONNID = '0400'.
ENDSELECT.
The above mentioned code can be more optimized by using the following code
SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
WHERE MANDT IN ( SELECT MANDT FROM T000 )
AND CARRID = 'LH'
AND CONNID = '0400'.
ENDSELECT.
3. Using buffered tables improves the performance considerably.
Bypassing the buffer increases the network considerably
SELECT SINGLE * FROM T100 INTO T100_WA
BYPASSING BUFFER
WHERE SPRSL = 'D'
AND ARBGB = '00'
AND MSGNR = '999'.
The above mentioned code can be more optimized by using the following code
SELECT SINGLE * FROM T100 INTO T100_WA
WHERE SPRSL = 'D'
AND ARBGB = '00'
AND MSGNR = '999'.
Select Statements Aggregate Functions
If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.
Some of the Aggregate functions allowed in SAP are MAX, MIN, AVG, SUM, COUNT, COUNT( * )
Consider the following extract.
Maxno = 0.
Select * from zflight where airln = LF and cntry = IN.
Check zflight-fligh > maxno.
Maxno = zflight-fligh.
Endselect.
The above mentioned code can be much more optimized by using the following code.
Select max( fligh ) from zflight into maxno where airln = LF and cntry = IN.
Select Statements For All Entries
The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
The plus
Large amount of data
Mixing processing and reading of data
Fast internal reprocessing of data
Fast
The Minus
Difficult to program/understand
Memory could be critical (use FREE or PACKAGE size)
Points to be must considered FOR ALL ENTRIES
Check that data is present in the driver table
Sorting the driver table
Removing duplicates from the driver table
Consider the following piece of extract
Loop at int_cntry.
Select single * from zfligh into int_fligh
where cntry = int_cntry-cntry.
Append int_fligh.
Endloop.
The above mentioned can be more optimized by using the following code.
Sort int_cntry by cntry.
Delete adjacent duplicates from int_cntry.
If NOT int_cntry[] is INITIAL.
Select * from zfligh appending table int_fligh
For all entries in int_cntry
Where cntry = int_cntry-cntry.
Endif.
Select Statements Select Over more than one Internal table
1. Its better to use a views instead of nested Select statements.
SELECT * FROM DD01L INTO DD01L_WA
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T INTO DD01T_WA
WHERE DOMNAME = DD01L_WA-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L_WA-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
The above code can be more optimized by extracting all the data from view DD01V_WA
SELECT * FROM DD01V INTO DD01V_WA
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT
2. To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.
SELECT * FROM EKKO INTO EKKO_WA.
SELECT * FROM EKAN INTO EKAN_WA
WHERE EBELN = EKKO_WA-EBELN.
ENDSELECT.
ENDSELECT.
The above code can be much more optimized by the code written below.
SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
FROM EKKO AS P INNER JOIN EKAN AS F
ON PEBELN = FEBELN.
3. Instead of using nested Select loops it is often better to use subqueries.
SELECT * FROM SPFLI
INTO TABLE T_SPFLI
WHERE CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK'.
SELECT * FROM SFLIGHT AS F
INTO SFLIGHT_WA
FOR ALL ENTRIES IN T_SPFLI
WHERE SEATSOCC < F~SEATSMAX
AND CARRID = T_SPFLI-CARRID
AND CONNID = T_SPFLI-CONNID
AND FLDATE BETWEEN '19990101' AND '19990331'.
ENDSELECT.
The above mentioned code can be even more optimized by using subqueries instead of for all entries.
SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA
WHERE SEATSOCC < F~SEATSMAX
AND EXISTS ( SELECT * FROM SPFLI
WHERE CARRID = F~CARRID
AND CONNID = F~CONNID
AND CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK' )
AND FLDATE BETWEEN '19990101' AND '19990331'.
ENDSELECT.
1. Table operations should be done using explicit work areas rather than via header lines.
READ TABLE ITAB INTO WA WITH KEY K = 'X BINARY SEARCH.
IS MUCH FASTER THAN USING
READ TABLE ITAB INTO WA WITH KEY K = 'X'.
If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
2. Always try to use binary search instead of linear search. But dont forget to sort your internal table before that.
READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
3. A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.
4. A binary search using secondary index takes considerably less time.
5. LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally.
LOOP AT ITAB INTO WA WHERE K = 'X'.
ENDLOOP.
The above code is much faster than using
LOOP AT ITAB INTO WA.
CHECK WA-K = 'X'.
ENDLOOP.
6. Modifying selected components using MODIFY itab TRANSPORTING f1 f2.. accelerates the task of updating a line of an internal table.
WA-DATE = SY-DATUM.
MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.
The above code is more optimized as compared to
WA-DATE = SY-DATUM.
MODIFY ITAB FROM WA INDEX 1.
7. Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably
Modifying selected components only makes the program faster as compared to Modifying all lines completely.
e.g,
LOOP AT ITAB ASSIGNING <WA>.
I = SY-TABIX MOD 2.
IF I = 0.
<WA>-FLAG = 'X'.
ENDIF.
ENDLOOP.
The above code works faster as compared to
LOOP AT ITAB INTO WA.
I = SY-TABIX MOD 2.
IF I = 0.
WA-FLAG = 'X'.
MODIFY ITAB FROM WA.
ENDIF.
ENDLOOP.
8. If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
LOOP AT ITAB1 INTO WA1.
READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.
IF SY-SUBRC = 0.
ADD: WA1-VAL1 TO WA2-VAL1,
WA1-VAL2 TO WA2-VAL2.
MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.
ELSE.
INSERT WA1 INTO ITAB2 INDEX SY-TABIX.
ENDIF.
ENDLOOP.
The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by
LOOP AT ITAB1 INTO WA.
COLLECT WA INTO ITAB2.
ENDLOOP.
SORT ITAB2 BY K.
COLLECT, however, uses a hash algorithm and is therefore independent
of the number of entries (i.e. O(1)) .
9. "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to LOOP-APPEND-ENDLOOP.
APPEND LINES OF ITAB1 TO ITAB2.
This is more optimized as compared to
LOOP AT ITAB1 INTO WA.
APPEND WA TO ITAB2.
ENDLOOP.
10. DELETE ADJACENT DUPLICATES accelerates the task of deleting duplicate entries considerably as compared to READ-LOOP-DELETE-ENDLOOP.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.
This is much more optimized as compared to
READ TABLE ITAB INDEX 1 INTO PREV_LINE.
LOOP AT ITAB FROM 2 INTO WA.
IF WA = PREV_LINE.
DELETE ITAB.
ELSE.
PREV_LINE = WA.
ENDIF.
ENDLOOP.
11. "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to DO -DELETE-ENDDO.
DELETE ITAB FROM 450 TO 550.
This is much more optimized as compared to
DO 101 TIMES.
DELETE ITAB INDEX 450.
ENDDO.
12. Copying internal tables by using ITAB2[ ] = ITAB1[ ] as compared to LOOP-APPEND-ENDLOOP.
ITAB2[] = ITAB1[].
This is much more optimized as compared to
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
APPEND WA TO ITAB2.
ENDLOOP.
13. Specify the sort key as restrictively as possible to run the program faster.
SORT ITAB BY K. makes the program runs faster as compared to SORT ITAB.
Internal Tables contd
Hashed and Sorted tables
1. For single read access hashed tables are more optimized as compared to sorted tables.
2. For partial sequential access sorted tables are more optimized as compared to hashed tables
Hashed And Sorted Tables
Point # 1
Consider the following example where HTAB is a hashed table and STAB is a sorted table
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
IF SY-SUBRC = 0.
ENDIF.
ENDDO.
This runs faster for single read access as compared to the following same code for sorted table
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE STAB INTO WA WITH TABLE KEY K = N.
IF SY-SUBRC = 0.
ENDIF.
ENDDO.
Point # 2
Similarly for Partial Sequential access the STAB runs faster as compared to HTAB
LOOP AT STAB INTO WA WHERE K = SUBKEY.
ENDLOOP.
This runs faster as compared to
LOOP AT HTAB INTO WA WHERE K = SUBKEY.
ENDLOOP. -
Need help with performance & memory tuning in a data warehousing environment
Dear All,
Good Day.
We had successfully migrated from a 4 node half-rack V2 Exadata to a 2 node quarter rack X4-2 Exadata. However, we are facing some issues with performance only for few loads while others have in fact shown good improvement.
1. The total memory on the OS is 250GB for each node (two compute nodes for a quarter rack).
2. Would be grateful if someone could help me with the best equation to calculate the SGA and PGA ( and also in allocation of shared_pool, large_pool etc) or whether Automatic Memory Management is advisable?
3. We had run exachk report which suggested us to configure huge pages.
4. When we tried to increase the SGA to more than 30GB the system doesn't allow us to do so. We had however set the PGA to 85GB.
5. Also, we had observed that some of the queries involving joins and indexes are taking longer time.
Any advise would be greatly appreciated.
Warm Regards,
Vikram.Hi Vikram,
There is no formula about SGA and PGA, but the best practices for OLTP environments is for a give ammount of memory (which cannot be up to 80% of total RAM from server) you should make 80% to SGA and 20% to PGA. For Data Warehouse envs, the values are like 60% SGA and 40% PGA or it can be up to 50%-50%. Also, some docs disencourage you to keep the database in Automatic Memory Management when you are using a big SGA (> 10G).
As you are using a RAC environment, you should configure Huge Pages. And if the systems are not allowing you to increase memory, just take a look at the semaphore parameters, probably they are set lower values. And for the poor performance queries, we need to see explain plans, table structure and you would also analyze if smart scan is playing the game.
Regards. -
URGENT!- ibook slowing down, NEED HELP BADLY
Good day.
When I bought my ibook, i upgraded the RAM of this right away. i added a 512MB RAM. I was happy with the way it was performing. After a few months, i decided to buy an externat 40GB hard drive because i found the internal hard drive too small and love downloading song and shows over the internet. after a few months, i noticed that my ibook slowed down. before, the "beachball " would seldom appear. now it appears alot. i just noticed that my ibook has really slowed down. i admit, i download a lot. but all these downloads go straight to the external hard drive. the files that i save in the internal hard drive are only excel, word, and pwerpoint files. very small. anyone can help me? is there something that i can use to speed up my ibooks performance? what should i do? is there such a thing as defragment (just like the one of a pc).Hi Michaelgnm,
Welcome to Apple Discussions
Try verifying and repairing permissions (Knowledge Base Document #106712 on Troubleshooting permissions issues in Mac OS X). Do you notice you slow during certain times. An example would be working an file from your external hard or using iPhoto. How much hard drive space do you have on your internal hard drive? You may want try deleting programs that you don't use (on my iBook I don't use Garage Band, iDVD, etc). Maybe freeing up some space can help speed things up.
A great program to show you exactly what is on your computer is WhatSize.
If you are going to use WhatSize to delete any files/programs/applications, please be careful and make sure you know exactly what you are deleting and if there are any repercussions. WhatSize will show you files that you would not normally see; they are referred to as "invisible files". These invisible files are hidden from the users view because they would clutter the desktop and they hold vital information that if corrupted or deleted may cause problems. Please make sure you know what you are doing!
Have you deleted files that you don't use; like for my iBook, GarageBand. I use GarageBand on my iMac because it is much easier and faster, so I deleted it on my iBook. Have you tried the "erase install method"? The reason for doing this is because Mac OS X installs all the necessary fonts, languages, drivers, etc that people all over the world my need, by default. This tends to take up some room that you might want to get rid of (make sure first what you don't need and need). You erase and install your system software (Knowledge Base Document 301270 About Install Options w/ Mac OS X 10.4), and when installing, do a custom install. This way you can install the languages, drivers, and applications you want. The same technique can be done with iLife.
Do you using any "pro" applications (Adobe Photo CS, Aperture, etc)? You may want to try using a program like OnyX to run some maintenance scripts.
I hope that helps,
Jon
Mac Mini 1.42Ghz, iPod (All), Airport (Graphite & Express), G4 1.33Ghz iBook, G4 iMac 1Ghz, G3 500Mhz, iBook iMac 233Mhz, eMate, Power Mac 5400 LC, PowerBook 540c, Macintosh 128K, Apple //e, Apple //, and some more... Mac OS X (10.4.5) Moto Razr, iLife '06, SmartDisk 160Gb, Apple BT Mouse, Sight..
Maybe you are looking for
-
I have created a small project that uses the same approach to monitoring stories as the one used in the GotoLastTextEdit sample project. The GotoLastTextEdit project example does the following: - Sets up a responder that monitor open/close signals fo
-
Java CDF hangs up Essbase application - Kindly help
Hi! I compiled the below java code which i am using to run a batch script from a calculation script using RUNJAVA. import java.*; import java.io.*; import com.hyperion.essbase.calculator.*; public class IRUN { public IRUN() { public static void main(
-
I have a Mid 2009 15 inch MacBook Pro with 2.53 GHz Intel Core 2 Duo and 4 GB 1067 MHz DDR3. Can this MacBook be upgraded to 8GB? If so, what type would you recomended
-
Approval Overview for SC and PO.
Hi experts, we use SRM 7.0 with BRF workflow. I need the approval data of SC and PO for such view in Mail: Approvingstep Status Approver GID Approver purchaser approved John Alex z00000001 approver approve
-
SCCM 2012 client installation not happening
Hi, I'm having issues while installing SCCM 2012 client on "Microsoftr Windows Serverr 2008 Standard SP-1" I have tried manual install and uninstall also several time. And all the revelent services are also working fine and I'm having below issue: So