I'm trying to improve the performance on a query that is running very slowly.
SELECT p.book_id AS payment_book_id, b.status AS book_status,
p.status AS payment_status, p.supplier_ref_no AS data_cash_ref,
f.train_pnr_no AS train_pnr, f.train_id AS train_ref_id,
f.service_no AS train_service_no, h.hotel_pnr_no AS hotel_pnr,
h.hotel_id AS hotel_ref_id, h.service_no AS hotel_service_no,
b.total_book_amt AS hotel_amt, c.car_pnr_no AS car_pnr,
c.car_id AS car_ref_id, c.service_no AS car_service_no,
b.book_date, b.promo_code
FROM gk_payment p
LEFT JOIN gk_book b ON b.book_id = p.book_id
LEFT JOIN gk_train_itiner_det f ON p.book_id = f.book_id
LEFT JOIN gk_hotel_itiner_det h ON p.book_id = h.book_id
LEFT JOIN gk_car_itiner_det c ON p.book_id = c.book_id
WHERE ((b.status IN ('8') AND p.status IN ('2', '0', '1', '8', '7')) OR
(b.status IN ('5') AND p.status IN ('3')) OR
(b.status IN ('11') AND p.status IN ('4', '5')))
AND p.service_no IS NOT NULL
AND b.book_type = 1
ORDER BY train_id, car_id
Some small comments about the query.
1) The first left join is not needed, since the where filter " AND b.book_type = 1" eliminates all cases where table b would be outer join (=empty).
FROM gk_payment p
LEFT JOIN gk_book b ON b.book_id = p.book_id
2) The status comparison can be written in a different way. This will probably not change anything performancewise
instead of
WHERE ((b.status IN ('8') AND p.status IN ('2', '0', '1', '8', '7')) OR
(b.status IN ('5') AND p.status IN ('3')) OR
(b.status IN ('11') AND p.status IN ('4', '5')))
you can write
WHERE ((b.status,p.status))
IN (('8','0')
,('8','1')
,('8','2')
,('8','7')
,('8','8')
,('5','3')
,('11','4')
,('11',53')
Which is imo much easier to read, maintain and checkable for completeness.
Furthermore: If the status fields are number columns then by all means compare them with numbers and not as strings.
3) Remove the order by condition
Is it faster without it? If yes, do you really need to order the output?
Similar Messages
-
HI All, How to improve the performance in given query?
HI All,
How to improve the performance in given query?
Query is..
PARAMETERS : p_vbeln type lips-vbeln.
DATA : par_charg TYPE LIPS-CHARG,
par_werks TYPE LIPS-WERKS,
PAR_MBLNR TYPE MSEG-MBLNR .
SELECT SINGLE charg
werks
INTO (par_charg, par_werks)
FROM lips
WHERE vbeln = p_vbeln.
IF par_charg IS NOT INITIAL.
SELECT single max( mblnr )
INTO par_mblnr
FROM mseg
WHERE bwart EQ '101'
AND werks EQ par_werks (index on werks only)
AND charg EQ par_charg.
ENDIF.
Regards
SteveHi steve,
Can't you use the material in your query (and not only the batch)?
I am assuming your system has an index MSEG~M by MANDT + MATNR + WERKS (+ other fields). Depending on your system (how many different materials you have), this will probably speed up the query considerably.
Anyway, in our system we ended up by creating an index by CHARG, but leave as a last option, only if selecting by matnr and werks is not good enough for your scenario.
Hope this helps,
Rui Dantas -
Please help me how to improve the performance of this query further.
Hi All,
Please help me how to improve the performance of this query further.
Thanks.Hi,
this is not your first SQL tuning request in this community -- you really should learn how to obtain performance diagnostics.
The information you posted is not nearly enough to even start troubleshooting the query -- you haven't specified elapsed time, I/O, or the actual number of rows the query returns.
The only piece of information we have is saying that your query executes within a second. If we believe this, then your query doesn't need tuning. If we don't, then we throw it away
and we're left with nothing.
Start by reading this blog post: Kyle Hailey » Power of DISPLAY_CURSOR
and applying this knowledge to your case.
Best regards,
Nikolay -
Ways to improve the performance of my query?
Hi all,
I have created a multi provider which enables to fetch the data from 3 ods. And each ods contains huge amount of data. As a result my query performance is very slow..
apart from creating indexes on ods? is there any other to be carried out to improve the performance of my query. Since all the 3 info providers are ods.
thanxs
harithaHaritha,
If you still need more info, just have a look below:
There are few ways your queries can be improved:
1. Your Data volume in your InfoProviders.
2. Dim table, how you have manage your objects into your dim table.
3. Query that runs from multiprovider vs cube itself. when running from multiproviders at the time of execution the system has to create more tables hence the query performance will be affected.
4. Aggregates into the cube, and they perfection of designing the aggregates.
5. OLAPCHACHE
6. Calculation formula
etc.
and also you can go thru the links below:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cccad390-0201-0010-5093-fd9ec8157802
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ce7fb368-0601-0010-64ba-fadc985a1f94
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/c8c4d794-0501-0010-a693-918a17e663cc
Hope this helps you.
****Assign Points*******
Gattu -
My MacBook is running very slowly. It takes an extremely long time to load an application, to respond to a command, and to quit an application. This has developed over the last month or so. Should I take to Apple Store? A friend suggested that I may need more RAM.
If you have 2GB of memory, that is the minimum required for OS X 10.7 Lion, however, many have found it needs 4GB+ to run reasonably well. Click on the apple on the left of the menu bar, then about this mac, to see how much memory you have.
To confirm if more memory will help, from Launchpad and utilities, load the Activity Monitor. Look at the system memory tab, specifically at page ins and page outs. If page outs is 10%-15% or more of page-ins, you can use more memory for what you run. When the system is low on memory OS X will write the contents of memory to the hard drive to make room for something else to run. Too much of this can impact performance. If you need more memory OWC and Crucial are both quality sources.
Also check your free hard drive space. Generally, you want 10% or more of the capacity to be free for systems usage. If free space gets too low, system performance will also be impacted. -
After upgrading to iOS 8.0 on my iPad 2, it is running very slowly and doesn't always respond to screen taps. Is OS8 the problem?
You aren't running a Classic operating system. See this tip on the correct place to post:
http://discussions.apple.com/docs/DOC-2463 -
Improving the performance of this query
Hi, Do you see any change we could do on this to improve its performance, pls, I appreciate you taking few minutes to help with analysing and tuining it
select hoc.hoc_id,
hoc.mstr_key_id,
address.DISP_NME,
blck.st_blck_id,
blck.mstr_key_id as blck_mstr_key,
bldg.BLDG_ID,
hoc.BLDG_KEY_ID,
address.OCPD_IND,
address.TP_TYPE_CDE,
'' as cmbcNumber,
'' as tpSiteNumber,
case
when address.cmbc_id is not null then amsowner.ams_038_direct_connect.GetMobilierForCMB(address.cmbc_id)
when address.lbc_id is not null and address.cmbc_id is null then amsowner.ams_038_direct_connect.GetMobilierForLBC(address.lbc_id)
END as Mobilier,
choice.cnsmr_chce_ind,
hoc.SRT_IND,
hoc.DLVRY_IND,
case valRES_STAT_CDE
when 123444 then hoc.cse_sprtn_wdth
when 123555 then hoc_pend.cse_sprtn_wdth
when 123666 then hoc_pend.cse_sprtn_wdth
end as cse_sprtn_wdth,
case valRES_STAT_CDE
when 123444 then hoc.admail_color_id
when 123555 then hoc.admail_color_id
when 123666 then hoc_pend.admail_color_id
end as admail_color_id,
case valRES_STAT_CDE
when 123444 then hoc.tieout
when 123555 then hoc_pend.tieout
when 123666 then hoc_pend.tieout
end as tieout,
hoc.callr_Ind,
hoc.PCKUP_ind,
case
when hldout.hld_out_id > 0 then 33
else 34
end as HLDOUT_IND,
case valRES_STAT_CDE
when 123444 then hoc.BREAKER_CARD_NUM
when 123555 then hoc_pend.BREAKER_CARD_NUM
when 123666 then hoc_pend.BREAKER_CARD_NUM
end as BREAKER_CARD_IND,
Case
when valRES_STAT_CDE = 123444 and hoc.MP_ID is not null and hoc.MP_ID <> 0 then 33
when valRES_STAT_CDE = 123555 and hoc_pend.MP_ID is not null and hoc_pend.MP_ID <> 0 then 33
when valRES_STAT_CDE = 123666 and hoc_pend.MP_ID is not null and hoc_pend.MP_ID <> 0 then 33
else 34 END as MP_IND,
case
when valRES_STAT_CDE = 123444 then hoc.LCRMS_SEQ_NUM
when valRES_STAT_CDE = 123555 then hoc_pend.DEL_SEQ
when valRES_STAT_CDE = 123666 then hoc_pend.DEL_SEQ
END as DEL_SEQ,
case
when (hoc_type_cde = 154 and hoc.MP_ID is not null ) then (NVL(mp.SLCLRES_RATE , 0)+ NVL(mp.OSSDRES_RATE,0))
when (hoc_type_cde = 154 and hoc.MP_ID is null ) then (NVL(asmt.SLCLRES_RATE , 0)+ NVL(asmt.OSSDRES_RATE,0))
when (hoc_type_cde = 156 and hoc.MP_ID is not null )then (NVL(mp.SLCLCOM_RATE,0) + NVL(mp.OSSDCOM_RATE,0))
when (hoc_type_cde = 156 and hoc.MP_ID is null ) then (NVL(asmt.SLCLCOM_RATE,0) + NVL(asmt.OSSDCOM_RATE,0))
else 0
END As AvgMail,
Case
when valRES_STAT_CDE = 123444 then hoc.drct_ind
when valRES_STAT_CDE = 123555 then hoc_pend.drct_ind
when valRES_STAT_CDE = 123666 then hoc_pend.drct_ind
END as drct_ind,
Case
when pc.ldu_type_cde in (492, 564, 565, 566, 567 ) then 33
else 34
end as lvr_ind,
hoc.A12_CARD_IND,
hoc.DNC_CARD_IND,
hoc.CARD_IND,
hoc.FRCE_CARD_IND,
hoc.EXTRA_CARD_NBR,
hoc.TTL_HOC_CNT,
--(select BSNS_NME_EN from occupant where occupant.ADDR_MAIL_ID = address.addr_id and occupant.prmry_ind = 33 and rownum <= 1 )as PRIMARY_BUS_NME_EN,
--(select BSNS_NME_FR from occupant where occupant.ADDR_MAIL_ID = address.addr_id and occupant.prmry_ind = 33 and rownum <= 1 )as PRIMARY_BUS_NME_FR,
blck.blck_seq,
address.ADDR_NUM,
address.ADDR_SFX_CDE,
address.ADDR_STE_NUM,
hoc.HOC_TYPE_CDE,
hoc.CSE_SPRTN_GRP_ID,
pc.pc_id As pc_id,
pc.disp_nme as pc_disp_nme,
hoc.bag_ind,
hoc.CASETAG,
occupant.BSNS_NME_EN as PRIMARY_BUS_NME_EN , occupant.BSNS_NME_FR as PRIMARY_BUS_NME_FR
from amsowner.AMS_038_HOC hoc
left join amsowner.ams_038_hoc_pndng hoc_pend
on hoc.MSTR_KEY_ID = hoc_pend.MSTR_KEY_ID
inner join amsowner.AMS_038_ST_BlCK blck
on hoc.st_blck_key_id = blck.mstr_key_id
inner join amsowner.postal_code pc
on blck.pc_id = pc.pc_id
left join amsowner.AMS_038_bldg bldg
on hoc.BLDG_KEY_ID = bldg.MSTR_KEY_ID
inner join amsowner.address address
on address.addr_id = hoc.addr_mail_id
inner join amsowner.addr_lctn_to_mail locToMail
on locToMail.addr_mail_id = address.addr_id
inner join amsowner.addr_chce choice
on choice.addr_id = locToMail.addr_lctn_id
left join occupant on (occupant.ADDR_MAIL_ID = address.addr_id and occupant.prmry_ind = 33)
left join amsowner.ams_038_hld_out hldout
on (hldout.mstr_key_id = hoc.mstr_key_id and hldout.end_dte is null)
left join amsowner.ams_038_dm dm
on dm.dm_id = blck.dm_id
left join ams_038_assmt asmt
on blck.pc_id = asmt.pc_id and asmt.dpt_cde_nme = valDpt_cde_nme and ((asmt.case_type_cde = 1220 and dm.a62_cse_ind = 33) or (asmt.case_type_cde = 1219 and dm.a62_cse_ind = 34))
left join ams_038_mail_prfl mp
on hoc.mp_id = mp.mp_id and ((mp.case_type_cde = 1220 and dm.a62_cse_ind = 33) or (mp.case_type_cde = 1219 and dm.a62_cse_ind = 34))
where hoc.mstr_key_id = valMSTR_KEY_ID and blck.DPT_CDE_NME = valDpt_cde_nme and hoc.DPT_CDE_NME = valDpt_cde_nme and blck.RSTRCTR_STAT_CDE = restCode;
Thanks a lot :)Hi and welcome to the forum.
I appreciate you taking few minutes to help with analysing and tuining itUnfortunatly it's not that simple.
We would need some more input here, like:
- database version
- optimizer settings
- execution plans
-etc..
Tuning is a complex matter, since many parameters come into play here.
If you want some useful responses then see:
[When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=3299435]
[How to post a SQLStatement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
to understand what information would also be very useful to us (and, if needed, have your DBA participating in this as well). -
Problem description:
Computer is slow
EtreCheck version: 2.1.5 (108)
Report generated January 11, 2015 at 4:45:09 PM EST
Click the [Support] links for help with non-Apple products.
Click the [Details] links for more information about that line.
Click the [Adware] links for help removing adware.
Hardware Information: ℹ️
MacBook Pro (13-inch, Early 2011) (Verified)
MacBook Pro - model: MacBookPro8,1
1 2.3 GHz Intel Core i5 CPU: 2-core
4 GB RAM Upgradeable
BANK 0/DIMM0
2 GB DDR3 1333 MHz ok
BANK 1/DIMM0
2 GB DDR3 1333 MHz ok
Bluetooth: Old - Handoff/Airdrop2 not supported
Wireless: en1: 802.11 a/b/g/n
Video Information: ℹ️
Intel HD Graphics 3000 - VRAM: 384 MB
Color LCD 1280 x 800
System Software: ℹ️
OS X 10.10 (14A389) - Uptime: 26 days 6:58:30
Disk Information: ℹ️
Hitachi HTS545032B9A302 disk0 : (320.07 GB)
EFI (disk0s1) <not mounted> : 210 MB
Recovery HD (disk0s3) <not mounted> [Recovery]: 650 MB
Macintosh HD (disk1) / : 318.84 GB (102.25 GB free)
Encrypted AES-XTS Unlocked
Core Storage: disk0s2 319.21 GB Online
MATSHITADVD-R UJ-8A8
USB Information: ℹ️
Apple Inc. FaceTime HD Camera (Built-in)
Apple Inc. Apple Internal Keyboard / Trackpad
Apple Inc. BRCM2070 Hub
Apple Inc. Bluetooth USB Host Controller
Apple Computer, Inc. IR Receiver
Thunderbolt Information: ℹ️
Apple Inc. thunderbolt_bus
Configuration files: ℹ️
/etc/hosts - Count: 200
Gatekeeper: ℹ️
Mac App Store and identified developers
Kernel Extensions: ℹ️
/Library/Extensions
[loaded] com.Cvnt.driver.CvntDriver (0206.01.97 - SDK 10.8) [Support]
[loaded] com.Cvnt.nke (0206.01.97 - SDK 10.8) [Support]
Problem System Launch Agents: ℹ️
[killed] com.apple.CallHistoryPluginHelper.plist
[killed] com.apple.CallHistorySyncHelper.plist
[killed] com.apple.cmfsyncagent.plist
[killed] com.apple.coreservices.appleid.authentication.plist
[killed] com.apple.printtool.agent.plist
[killed] com.apple.rcd.plist
[killed] com.apple.scopedbookmarkagent.xpc.plist
7 processes killed due to memory pressure
Problem System Launch Daemons: ℹ️
[killed] com.apple.AssetCacheLocatorService.plist
[killed] com.apple.ctkd.plist
[killed] com.apple.findmymac.plist
[killed] com.apple.ifdreader.plist
[killed] com.apple.nehelper.plist
[killed] com.apple.periodic-monthly.plist
[killed] com.apple.periodic-weekly.plist
[killed] com.apple.tccd.system.plist
[killed] com.apple.wdhelper.plist
9 processes killed due to memory pressure
Launch Agents: ℹ️
[running] com.Cvnt.start.plist [Support]
[loaded] com.oracle.java.Java-Updater.plist [Support]
Launch Daemons: ℹ️
[loaded] com.adobe.fpsaud.plist [Support]
[loaded] com.cvnt.cehostsd.plist [Support]
[running] com.cvnt.celapid.plist [Support]
[loaded] com.Cvnt.daemon.plist [Support]
[loaded] com.microsoft.office.licensing.helper.plist [Support]
[loaded] com.oracle.java.Helper-Tool.plist [Support]
[loaded] com.oracle.java.JavaUpdateHelper.plist [Support]
User Launch Agents: ℹ️
[loaded] com.adobe.ARM.[...].plist [Support]
[failed] com.facebook.videochat.[redacted].plist [Support]
[loaded] com.google.keystone.agent.plist [Support]
[running] com.spotify.webhelper.plist [Support]
User Login Items: ℹ️
Garmin Express Service Application (/Applications/Garmin Express.app/Contents/Library/LoginItems/Garmin Express Service.app)
iTunesHelper UNKNOWNHidden (missing value)
AdobeResourceSynchronizer ApplicationHidden (/Applications/Adobe Reader.app/Contents/Support/AdobeResourceSynchronizer.app)
Dropbox Application (/Applications/Dropbox.app)
Spotify Application (/Applications/Spotify.app)
Internet Plug-ins: ℹ️
Default Browser: Version: 600 - SDK 10.10
Flip4Mac WMV Plugin: Version: 3.0.0.126 - SDK 10.8 [Support]
AmazonMP3DownloaderPlugin101750: Version: AmazonMP3DownloaderPlugin 1.0.17 - SDK 10.4 [Support]
AdobePDFViewerNPAPI: Version: 11.0.10 - SDK 10.6 [Support]
FlashPlayer-10.6: Version: 15.0.0.246 - SDK 10.6 [Support]
McGraw Hill ChemDraw: Version: 12.0.3 [Support]
Silverlight: Version: 5.1.30514.0 - SDK 10.6 [Support]
Flash Player: Version: 15.0.0.246 - SDK 10.6 Mismatch! Adobe recommends 16.0.0.235
QuickTime Plugin: Version: 7.7.3
AmazonMP3DownloaderPlugin: Version: AmazonMP3DownloaderPlugin 1.0.17 - SDK 10.4 [Support]
SharePointBrowserPlugin: Version: 14.4.4 - SDK 10.6 [Support]
AdobePDFViewer: Version: 11.0.10 - SDK 10.6 [Support]
JavaAppletPlugin: Version: Java 8 Update 25 Check version
Safari Extensions: ℹ️
AdBlock [Installed]
Covenant Eyes [Installed]
3rd Party Preference Panes: ℹ️
Flash Player [Support]
Flip4Mac WMV [Support]
Java [Support]
Time Machine: ℹ️
Auto backup: YES
Volumes being backed up:
Macintosh HD: Disk size: 318.84 GB Disk used: 216.59 GB
Destinations:
My Passport [Local]
Total size: 0 B
Total number of backups: 0
Oldest backup: -
Last backup: -
Size of backup disk: Too small
Backup size 0 B < (Disk used 216.59 GB X 3)
Top Processes by CPU: ℹ️
6% WindowServer
3% Spotify
1% firefox
1% hidd
0% AppleSpell
Top Processes by Memory: ℹ️
752 MB firefox
90 MB softwareupdated
48 MB mds
43 MB WindowServer
39 MB Spotify
Virtual Memory Information: ℹ️
29 MB Free RAM
983 MB Active RAM
975 MB Inactive RAM
1.19 GB Wired RAM
45.72 GB Page-ins
4.38 GB Page-outsBased in the Page swaps, additional RAM might prove to be beneficial. The best sources of Mac compatible RAM are OWC and Crucuial.
Ciao. -
Need help in improving the performance for the sql query
Thanks in advance for helping me.
I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. The data count which is updated in the target table is 2 million records and the target table has 15 million records.
Any suggestions or solutions for improving performance are appreciated
SQL query:
update targettable tt
set mnop = 'G',
where ( x,y,z ) in
select a.x, a.y,a.z
from table1 a
where (a.x, a.y,a.z) not in (
select b.x,b.y,b.z
from table2 b
where 'O' = b.defg
and mnop = 'P'
and hijkl = 'UVW';987981 wrote:
I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. And that meant what? Surely if you spend all that time and effort to try various approaches, it should mean something? Failures are as important teachers as successes. You need to learn from failures too. :-)
The data count which is updated in the target table is 2 million records and the target table has 15 million records.Tables have rows btw, not records. Database people tend to get upset when rows are called records, as records exist in files and a database is not a mere collection of records and files.
The failure to find a single faster method with the approaches you tried, points to that you do not know what the actual performance problem is. And without knowing the problem, you still went ahead, guns blazing.
The very first step in dealing with any software engineering problem, is to identify the problem. Seeing the symptoms (slow performance) is still a long way from problem identification.
Part of identifying the performance problem, is understanding the workload. Just what does the code task the database to do?
From your comments, it needs to find 2 million rows from 15 million rows. Change these rows. And then write 2 million rows back to disk.
That is not a small workload. Simple example. Let's say that the 2 million row find is 1ms/row and the 2 million row write is also 1ms/row. This means a 66 minute workload. Due to the number of rows, an increase in time/row either way, will potentially have 2 million fold impact.
So where is the performance problem? Time spend finding the 2 million rows (where other tables need to be read, indexes used, etc)? Time spend writing the 2 million rows (where triggers and indexes need to be fired and maintained)? Both? -
Improving the performance of Stored Procedure
need to improve the performance of this SP that is hitting two tables that holds about 24000 rowsUSE [trouble_database]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[the_trouble_StoredProcedure]
@troubleMedicatiotrouble_durationl int
as
declare @trouble_refil table
( troubleMedicatiotrouble_durationl int,
trouble_durationl int
declare @nRefillDispense int
if exists (select ml.lid from trouble_MedicaticDirectmd
inner join trouble_Medicatication ml on ml.troubleMedicatiotrouble_durationl=md.lID
where isnull(md.trouble_bRefillDisp,0)=1
and ml.lID <>(Select MIN(lID) from trouble_Medicatication where troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl)
begin
select @nRefillDispense = isnull(nRefillDispense,9) from trouble_MedicaticDirect where lID=@troubleMedicatiotrouble_durationl
insert @trouble_refil (trouble_durationl)
select
Case szIncrement
when 'Day(s)' then isnull(trouble_durationl,0)
when 'Week(s)' then isnull(trouble_durationl,0) * 7
when 'Month(s)' then isnull(trouble_durationl,0) * 30
when 'Year(s)' then isnull(trouble_durationl,0) * 365
else 0
end as trouble_durationl
from
trouble_Medicatication where
troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl
and lID<>(Select min(lID) from trouble_Medicatication where troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl)
select @nRefillDispense as nRefillDispense, sum(trouble_durationl)as trouble_durationl from @trouble_refil
end
else
select 0 as nRefillDispense,0 as trouble_durationl
kyou can use Execution plain
http://stackoverflow.com/questions/7359702/how-do-i-obtain-a-query-execution-plan
and add index.
Index according to the fields you ask queries can improve performance greatly larger!
You can use the statistics for building indexes:
http://www.mssqltips.com/sqlservertip/2979/querying-sql-server-index-statistics/
Tzuri Ben Ezra | My Certifications:
CompTIA A+ ,Microsoft MCP, MCTS, MCSA, MCITP |
FaceBook: Tzuri FaceBook | vCard:
Tzuri vCard |
Microsoft ID:
Microsoft Transcript
| -
Please guide to improve the performance of XML column reading query.
Hi Experts,
The below query is taking 45 seconds to return 170 records.
Due to selecting XMLTYPE column in query.
select *
from RANGE where WSNO = 3
order by PREFERENCE desc;
The total number of records in the table is 1060.
Even it's a very small table why it's taking 45 seconds.
Can anybody please help me on how to get the output in 2 to 3 seconds.
I want all the columns from the table.
The problem only with REST column XMLTYPE.
If I am not selecting this column I am getting output in 1 to 2 seconds.
I am posting the execution plan and DDL for table and index.
PLAN_TABLE_OUTPUT
Plan hash value: 3593186720
| SNO | Operation | EMPNAME | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 31 | 23281 | 21 (5)| 00:00:01 |
| 1 | SORT ORDER BY | | 31 | 23281 | 21 (5)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID | RANGE | 31 | 23281 | 20 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | INDX_WSNO | 31 | | 1 (0)| 00:00:01 |
Predicate Information (SNOentified by operation SNO):
3 - access("WSNO"=3)
CREATE TABLE RANGE
SNO NUMBER,
BUSNO NUMBER,
EMPNAME NVARCHAR2(64),
PREFERENCE NUMBER,
TSNO NUMBER,
MEMBER CHAR(1 CHAR) ,
EQU CHAR(1 CHAR) ,
REMAIL CHAR(1 CHAR) ,
SSR CHAR(1 CHAR) ,
SUB CHAR(1 CHAR) ,
SPN CHAR(1 CHAR) ,
SEMPNAME NVARCHAR2(128),
FVL NUMBER(32),
TVL NUMBER(32),
ISD CHAR(1 CHAR),
CHANGED NVARCHAR2(64),
CDATE TIMESTAMP(6) ,
UDBY NVARCHAR2(64),
UDATE TIMESTAMP(6),
LSTU CLOB,
WSNO NUMBER,
ASTN CHAR(1 CHAR),
ASTNPL CHAR(1 CHAR),
AVAF CHAR(1 CHAR),
REST SYS.XMLTYPE
TABLESPACE USERS
PCTUSED 0
PCTFREE 10
INITRANS 11
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
XMLTYPE REST STORE AS CLOB
( TABLESPACE USERS
ENABLE STORAGE IN ROW
CHUNK 8192
PCTVERSION 10
NOCACHE
INDEX (
TABLESPACE USERS
STORAGE (
INITIAL 64K
NEXT 1
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
LOB (LSTU) STORE AS
( TABLESPACE USERS
ENABLE STORAGE IN ROW
CHUNK 8192
RETENTION
NOCACHE
INDEX (
TABLESPACE USERS
STORAGE (
INITIAL 64K
NEXT 1
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOCACHE
NOPARALLEL
MONITORING;
CREATE INDEX INDX_WSNO ON RANGE(WSNO);
CREATE UNIQUE INDEX RULE_EMPNAME ON RANGE(BUSNO, EMPNAME);
Please help me how to improve the performance of this query.
Thanks.Can you try something like this and check if its faster? (this is just my guess as I dont have your data )
SELECT SNO,
BUSNO,
EMPNAME,
PREFERENCE,
TSNO,
MEMBER,
EQU,
REMAIL,
SSR,
SUB,
SPN,
SEMPNAME,
FVL,
TVL,
ISD,
CHANGED,
CDATE,
UDBY,
UDATE,
LSTU,
WSNO,
ASTN,
ASTNPL,
AVAF,
xmltype.getclobval (rest) rest
FROM RANGE
WHERE wsno = 3
order by PREFERENCE desc;
Cheers,
Manik. -
Imporving the performance of a query
Hi,
I have the following query in Oracle:
SELECT distinct VECTOR_ID FROM SUMMARY_VECTOR where CASE_NAME like 'BASECASE_112_ECLIPSE100'
"SUMMARY_VECTOR" contains approximately 120 million records or tuples. So the total time for this query is about 62 seconds
I want to improve the performance of this query. How can I achieve this ?
any hint ?
ThanksPLAN_TABLE_OUTPUT
Plan hash value: 3042243244
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 1 | 29 | 182K (3)| 00:36
:28 |
| 1 | SORT AGGREGATE | | 1 | 29 | |
|
|* 2 | TABLE ACCESS FULL| SUMMARY_VECTOR | 4323K| 119M| 182K (3)| 00:36
:28 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
2 - filter("CASE_NAME"='BASECASE_112_ECLIPSE100')
14 rows selected. -
I just updated my Macbook (2010) to Yosemite, and it's become very slow. After searching through this community, I downloaded and run EtreCheck, but don't understand what the report means. Please could you help me with what I should do to improve my computer's speed, aside from upgrading my RAM? Thank you so much.
The report:
Problem description:
my macbook is running very slowly after upgrading to yosemite.
EtreCheck version: 2.0.11 (98)
Report generated 12 November 2014 1:44:14 pm SGT
Hardware Information: ℹ️
MacBook (13-inch, Mid 2010) (Verified)
MacBook - model: MacBook7,1
1 2.4 GHz Intel Core 2 Duo CPU: 2-core
2 GB RAM Upgradeable
BANK 0/DIMM0
1 GB DDR3 1067 MHz ok
BANK 1/DIMM0
1 GB DDR3 1067 MHz ok
Bluetooth: Old - Handoff/Airdrop2 not supported
Wireless: en1: 802.11 a/b/g/n
Video Information: ℹ️
NVIDIA GeForce 320M - VRAM: 256 MB
Color LCD 1280 x 800
System Software: ℹ️
OS X 10.10 (14A389) - Uptime: 3:23:3
Disk Information: ℹ️
TOSHIBA MK2555GSXF disk0 : (250.06 GB)
S.M.A.R.T. Status: Verified
EFI (disk0s1) <not mounted> : 210 MB
Macintosh HD (disk0s2) / [Startup]: 249.20 GB (25.42 GB free)
Recovery HD (disk0s3) <not mounted> [Recovery]: 650 MB
HL-DT-ST DVDRW GS23N
USB Information: ℹ️
Western Digital My Passport 0748 1 TB
S.M.A.R.T. Status: Verified
EFI (disk1s1) <not mounted> : 210 MB
tansey (disk1s2) /Volumes/tansey : 999.83 GB (951.98 GB free)
Apple Inc. Built-in iSight
Apple Inc. BRCM2070 Hub
Apple Inc. Bluetooth USB Host Controller
Apple Inc. Apple Internal Keyboard / Trackpad
Configuration files: ℹ️
/etc/hosts - Count: 15
Gatekeeper: ℹ️
Mac App Store and identified developers
Kernel Extensions: ℹ️
/System/Library/Extensions
[not loaded] com.NovatelWireless.driver.NovatelWirelessUSBCDCECMControl (3.0.13) Support
[not loaded] com.NovatelWireless.driver.NovatelWirelessUSBCDCECMData (3.0.13) Support
[not loaded] com.ZTE.driver.ZTEUSBCDCACMData (1.3.8) Support
[not loaded] com.ZTE.driver.ZTEUSBMassStorageFilter (1.3.8) Support
[not loaded] com.novamedia.driver.IceraUSB_MSD_Bypass (1.3.0) Support
[not loaded] com.novatelwireless.driver.3G (3.0.13) Support
[not loaded] com.novatelwireless.driver.DisableAutoInstall (3.0.13) Support
[not loaded] com.option.driver.Option72 (2.15.0) Support
[not loaded] com.option.driver.OptionHS (3.26.0) Support
[not loaded] com.option.driver.OptionMSD (1.21.0) Support
[not loaded] com.option.driver.OptionQC (1.11.0) Support
[not loaded] com.rim.driver.BlackBerryUSBDriverInt (0.0.39) Support
[not loaded] com.rim.driver.BlackBerryUSBDriverVSP (0.0.45) Support
[not loaded] com.vodafone.driver (3.0.9) Support
[not loaded] com.zte.driver.cdc_ecm_qmi (1.0.1) Support
[not loaded] com.zte.driver.cdc_usb_bus (1.0.1) Support
[not loaded] de.novamedia.driver.NMSamsung (0.0.2) Support
[not loaded] de.novamedia.driver.NMSmartplugSCSIDevice (1.0.1) Support
[not loaded] de.novamedia.oem.vodafone.vtp.huawei.cdc (0.0.2) Support
/System/Library/Extensions/NMHuaweiPhonesVTPCDC_106.kext/Contents/PlugIns
[not loaded] de.novamedia.driver.NMUSBCDCACMControl (3.2.12) Support
/System/Library/Extensions/NMSamsungDriver_106.kext/Contents/PlugIns
[not loaded] de.novamedia.driver.NMUSBCDCACMData (3.2.12) Support
/System/Library/Extensions/NovatelWireless3G.kext/Contents/PlugIns
[not loaded] com.novatelwireless.driver.3GData (3.0.13) Support
/System/Library/Extensions/Vodafone.kext/Contents/PlugIns
[not loaded] com.vodafone.driver.Data (3.0.9) Support
Startup Items: ℹ️
HP IO: Path: /Library/StartupItems/HP IO
HWNetMgr: Path: /Library/StartupItems/HWNetMgr
HWPortDetect: Path: /Library/StartupItems/HWPortDetect
Startup items are obsolete and will not work in future versions of OS X
Problem System Launch Agents: ℹ️
[failed] com.apple.accountsd.plist
[failed] com.apple.AirPlayUIAgent.plist
[failed] com.apple.bird.plist
[failed] com.apple.CallHistoryPluginHelper.plist
[failed] com.apple.CallHistorySyncHelper.plist
[failed] com.apple.cloudd.plist
[failed] com.apple.coreservices.appleid.authentication.plist
[failed] com.apple.coreservices.uiagent.plist
[failed] com.apple.EscrowSecurityAlert.plist
[failed] com.apple.icloud.fmfd.plist
[failed] com.apple.iconservices.iconservicesagent.plist
[failed] com.apple.nsurlsessiond.plist
[failed] com.apple.pluginkit.pkd.plist
[failed] com.apple.recentsd.plist
[failed] com.apple.security.cloudkeychainproxy.plist
[failed] com.apple.spindump_agent.plist
[failed] com.apple.telephonyutilities.callservicesd.plist
Problem System Launch Daemons: ℹ️
[failed] com.apple.awdd.plist
[failed] com.apple.cache_delete.plist
[failed] com.apple.coresymbolicationd.plist
[failed] com.apple.ctkd.plist
[failed] com.apple.diagnosticd.plist
[failed] com.apple.iconservices.iconservicesagent.plist
[failed] com.apple.iconservices.iconservicesd.plist
[failed] com.apple.ifdreader.plist
[failed] com.apple.installd.plist
[failed] com.apple.MobileFileIntegrity.plist
[failed] com.apple.nehelper.plist
[failed] com.apple.nsurlsessiond.plist
[failed] com.apple.sandboxd.plist
[failed] com.apple.softwareupdated.plist
[failed] com.apple.spindump.plist
[failed] com.apple.sysmond.plist
[failed] com.apple.tccd.system.plist
[failed] com.apple.wdhelper.plist
[failed] com.apple.xpc.smd.plist
[running] de.novamedia.nmnetmgrd.plist Support
Launch Agents: ℹ️
[not loaded] com.adobe.AAM.Updater-1.0.plist Support
[failed] com.adobe.CS5ServiceManager.plist Support
[loaded] com.google.keystone.agent.plist Support
[running] de.novamedia.VodafoneDeviceObserver.plist Support
[invalid?] SwapperUFi.plist Support
Launch Daemons: ℹ️
[loaded] com.adobe.fpsaud.plist Support
[invalid?] com.adobe.SwitchBoard.plist Support
[loaded] com.cloudpath.maccmd.plist Support
[loaded] com.google.keystone.daemon.plist Support
[loaded] com.microsoft.office.licensing.helper.plist Support
[invalid?] PPPMonitord.plist Support
User Launch Agents: ℹ️
[loaded] com.adobe.ARM.[...].plist Support
[invalid?] com.akamai.client.plist Support
[invalid?] com.divx.agent.postinstall.plist Support
[failed] com.facebook.videochat.[redacted].plist Support
User Login Items: ℹ️
Dropbox Application (/Applications/Dropbox.app)
SurplusMeterAgent UNKNOWN (missing value)
Google Chrome ApplicationHidden (/Applications/Google Chrome.app)
HP Scheduler Application (/Library/Application Support/Hewlett-Packard/Software Update/HP Scheduler.app)
Internet Plug-ins: ℹ️
o1dbrowserplugin: Version: 5.38.6.0 - SDK 10.8 Support
Google Earth Web Plug-in: Version: 7.1 Support
Default Browser: Version: 600 - SDK 10.10
OfficeLiveBrowserPlugin: Version: 12.2.6 Support
OVSHelper: Version: 1.1 Support
AdobePDFViewerNPAPI: Version: 10.1.12 Support
FlashPlayer-10.6: Version: 15.0.0.152 - SDK 10.6 Support
Silverlight: Version: 5.1.10411.0 - SDK 10.6 Support
Flash Player: Version: 15.0.0.152 - SDK 10.6 Mismatch! Adobe recommends 15.0.0.223
iPhotoPhotocast: Version: 7.0
googletalkbrowserplugin: Version: 5.38.6.0 - SDK 10.8 Support
QuickTime Plugin: Version: 7.7.3
AdobePDFViewer: Version: 10.1.12 Support
SharePointBrowserPlugin: Version: 14.0.0 Support
JavaAppletPlugin: Version: 15.0.0 - SDK 10.10 Check version
User Internet Plug-ins: ℹ️
OctoshapeWeb: Version: 1.0 Support
Safari Extensions: ℹ️
DivX Plus Web Player HTML5 <video>
3rd Party Preference Panes: ℹ️
DivX Support
Flash Player Support
Time Machine: ℹ️
Skip System Files: NO
Auto backup: NO - Auto backup turned off
Volumes being backed up:
Macintosh HD: Disk size: 249.20 GB Disk used: 223.78 GB
Destinations:
Time Machine Backups [Local]
Total size: 0 B
Total number of backups: 0
Oldest backup: -
Last backup: -
Size of backup disk: Too small
Backup size 0 B < (Disk used 223.78 GB X 3)
Top Processes by CPU: ℹ️
15% WindowServer
1% Dropbox
0% AppleSpell
0% Skype
0% imagent
Top Processes by Memory: ℹ️
60 MB Google Chrome
56 MB JavaApplicationStub
47 MB Skype
45 MB Finder
45 MB WindowServer
Virtual Memory Information: ℹ️
60 MB Free RAM
443 MB Active RAM
398 MB Inactive RAM
349 MB Wired RAM
16.91 GB Page-ins
633 MB Page-outsI advise to reply to the one you want to reply to.
You have had good information here. I will not repeat that here.
I would like to add:
you have incompatible software: start in SafeMode, read Woodmeister and see if it is free of issues.
Akamai is crap software needed or not, Huawei the same.
It is very possible that the keygenerator you used for generating a key for some softwares has infected your mac.
The non-regular software with the false key(s) are not compatible probably or generate malware. Luckily you can not update them automatically because the keygenerator blocked the software for contacting the developer... I propose to consider getting rid of those softwares by really good uninstalling.
You have a beautiful mac, don't degenerate it with crapped software. There are alternatives for expensive software, for example Adobe Photoshop has a free alternative (with a less beautiful interface) in GIMP. And so on.
Lex -
Re: How to Improve the performance on Rollup of Aggregates for PCA Infocube
Hi BW Guru's,
I have unresolved issue and our team is still working on it.
I have already posted several questions on this but not clear on how to reduce the time on Rollup of Aggregates process.
I have requested for OSS note and searching myself but still could not found.
Finally i have executed one of the cube in RSRV with the database selection
"Database indexes of an InfoCube and its aggregates" and got warning messages i was tried to correct the error and executed once again but still i found warning message. and the error message are as follows: (this is only for one info cube we got 6 info cubes i am executing one by one).
ORACLE: Index /BI0/IACCOUNT~0 has possibly degenerated
ORACLE: Index /BI0/IPROFIT_CTR~0 has possibly degenerated
ORACLE: Index /BI0/SREQUID~0 has possibly degenerated
ORACLE: Index /BIC/D1001072~010 has possibly degenerated
ORACLE: Index /BIC/D1001132~010 has possibly degenerated
ORACLE: Index /BIC/D1001212~010 has possibly degenerated
ORACLE: Index /BIC/DGPCOGC062~01 has possibly degenerated
ORACLE: Index /BIC/IGGRA_CODE~0 has possibly degenerated
ORACLE: Index /BIC/QGMAPGP1~0 has possibly degenerated
ORACLE: Index /BIC/QGMAPPC2~0 has possibly degenerated
ORACLE: Index /BIC/SGMAPGP1~0 has possibly degenerated
i don't know how to move further on this can any one tell me how to tackle this problem to increase the performance on Rollup of Aggregates (PCA Info cubes).
every time i use to create index and statistics regularly to improve the performance it will work for couple of days and again the performance of the rollup of aggregates come down gradually.
Thanks and Regards,
Venkathi,
check in a sql client the sql created by Bi and the query that you use directy from your physical layer...
The time between these 2 must be 2-3 seconds,otherwise you have problems.(these seconds are for scripts that needed by Bi)
If you use "like" in your sql then forget indexes....
For more informations about indexes check google or your Dba .
Last, i mentioned that materialize view is not perfect,it help a lot..so why not try to split it to smaller ones....
ex...
logiacal dimensions
year-half-day
company-department
fact
quantity
instead of making one...make 3,
year - department - quantity
half - department - quantity
day - department - quantity
and add them as datasource and assign them the appropriate logical level at bussiness layer in administrator...
Do you use partioning functionality???
i hope i helped....
http://greekoraclebi.blogspot.com/
/////////////////////////////////////// -
Help to improve the performance of a procedure.
Hello everybody,
First to introduce myself. My name is Ivan and I recently started learning SQL and PL/SQL. So don't go hard on me. :)
Now let's jump to the problem. What we have there is a table (big one, but we'll need only a few fields) with some information about calls. It is called table1. There is also another one, absolutely the same structure, which is empty and we have to transfer the records from the first one.
The shorter calls (less than 30 minutes) have segmentID = 'C1'.
The longer calls (more than 30 minutes) are recorded as more than one record (1 for every 30 minutes). The first record (first 30 minutes of the call) has segmentID = 'C21'. It is the first so we have only one of these for every different call. Then we have the next (middle) parts of the call, which have segmentID = 'C22'. We can have more than 1 middle part and again the maximum minutes in each is 30 minutes. Then we have the last part (again max 30 minutes) with segmentID = 'C23'. As with the first one we can have only one last part.
So far, so good. Now we need to insert these call records into the second table. The C1 are easy - one record = one call. But the partial ones we need to combine so they become one whole call. This means that we have to take one of the first parts (C21), find if there is a middle part (C22) with the same calling/called numbers and with 30 minutes difference in date/time, then search again if there is another C22 and so on. And last we have to search for the last part of the call (C23). In the course of these searches we sum the duration of each part so we can have the duration of the whole call at the end. Then we are ready to insert it in the new table as a single record, just with new duration.
But here comes the problem with my code... The table has A LOT of records and this solution, despite the fact that it works (at least in the tests I've made so far), it's REALLY slow.
As I said I'm new to PL/SQL and I know that this solution is really newbish, but I can't find another way of doing this.
So I decided to come here and ask you for some tips on how to improve the performance of this.
I think you are getting confused already, so I'm just going to put some comments in the code.
I know it's not a procedure as it stands now, but it will be once I create a better code. I don't think it matters for now.
DECLARE
CURSOR cur_c21 IS
select * from table1
where segmentID = 'C21'
order by start_date_of_call; // in start_date_of_call is located the beginning of a specific part of the call. It's date format.
CURSOR cur_c22 IS
select * from table1
where segmentID = 'C22'
order by start_date_of_call;
CURSOR cur_c22_2 IS
select * from table1
where segmentID = 'C22'
order by start_date_of_call;
cursor cur_c23 is
select * from table1
where segmentID = 'C23'
order by start_date_of_call;
v_temp_rec_c22 cur_c22%ROWTYPE;
v_dur table1.duration%TYPE; // using this for storage of the duration of the call. It's number.
BEGIN
insert into table2
select * from table1 where segmentID = 'C1'; // inserting the calls which are less than 30 minutes long
-- and here starts the mess
FOR rec_c21 IN cur_c21 LOOP // taking the first part of the call
v_dur := rec_c21.duration; // recording it's duration
FOR rec_c22 IN cur_c22 LOOP // starting to check if there is a middle part for the call
IF rec_c22.callingnumber = rec_c21.callingnumber AND rec_c22.callednumber = rec_c21.callednumber AND
(rec_c22.start_date_of_call - rec_c21.start_date_of_call) = (1/48)
/* if the numbers are the same and the date difference is 30 minutes then we have a middle part and we start searching for the next middle. */
THEN
v_dur := v_dur + rec_c22.duration; // updating the new duration
v_temp_rec_c22:=rec_c22; // recording the current record in another variable because I use it for the next check
FOR rec_c22_2 in cur_c22_2 LOOP
IF rec_c22_2.callingnumber = v_temp_rec_c22.callingnumber AND rec_c22_2.callednumber = v_temp_rec_c22.callednumber AND
(rec_c22_2.start_date_of_call - v_temp_rec_c22.start_date_of_call) = (1/48)
/* logic is the same as before but comparing with the last value in v_temp...
And because the data in the cursors is ordered by date in ascending order it's easy to search for another middle parts. */
THEN
v_dur:=v_dur + rec_c22_2.duration;
v_temp_rec_c22:=rec_c22_2;
END IF;
END LOOP;
END IF;
EXIT WHEN rec_c22.callingnumber = rec_c21.callingnumber AND rec_c22.callednumber = rec_c21.callednumber AND
(rec_c22.start_date_of_call - rec_c21.start_date_of_call) = (1/48);
/* exiting the loop if we have at least one middle part.
(I couldn't find if there is a way to write this more clean, like exit when (the above if is true) */
END LOOP;
FOR rec_c23 IN cur_c23 LOOP
IF (rec_c23.callingnumber = rec_c21.callingnumber AND rec_c23.callednumber = rec_c21.callednumber AND
(rec_c23.start_date_of_call - rec_c21.start_date_of_call) = (1/48)) OR v_dur != rec_c21.duration
/* we should always have one last part, so we need this check.
If we don't have the "v_dur != rec_c21.duration" part it will execute the code inside only if we don't have middle parts
(yes we can have these situations in calls longer than 30 and less than 60 minutes). */
THEN
v_dur:=v_dur + rec_c23.duration;
rec_c21.duration:=v_dur; // updating the duration
rec_c21.segmentID :='C1';
INSERT INTO table2 VALUES rec_c21; // inserting the whole call in table2
END IF;
EXIT WHEN (rec_c23.callingnumber = rec_c21.callingnumber AND rec_c23.callednumber = rec_c21.callednumber AND
(rec_c23.start_date_of_call - rec_c21.start_date_of_call) = (1/48)) OR v_dur != rec_c21.duration;
// exit the loop when the last part has been found.
END LOOP;
END LOOP;
END;I'm using Oracle 11g and version 1.5.5 of SQL Developer.
It's my first post here so hope this is the right sub-forum.
I tried to explain everything as deep as possible (sorry if it's too long) and I kinda think that the code got somehow hard to read with all these comments. If you want I can remove them.
I know I'm still missing a lot of knowledge so every help is really appreciated.
Thank you very much in advance!Atiel wrote:
Thanks for the suggestion but the thing is that segmentID must stay the same for all. The data in this field is just to tell us if this is a record of complete call (C1) or a partial record of a call(C21, C22, C23). So in table2 as every record will be a complete call the segmentID must be C1 for all.Well that's not a problem. You just hard code 'C1' instead of applying the row number as I was doing:
SQL> ed
Wrote file afiedt.buf
1 select 'C1' as segmentid
2 ,start_date_of_call, duration, callingnumber, callednumber
3 from (
4 select distinct
5 min(start_date_of_call) over (partition by callingnumber, callednumber) as start_date_of_call
6 ,sum(duration) over (partition by callingnumber, callednumber) as duration
7 ,callingnumber
8 ,callednumber
9 from table1
10* )
SQL> /
SEGMENTID START_DATE_OF_CALL DURATION CALLINGNUMBER CALLEDNUMBER
C1 11-MAY-2012 12:13:10 8020557824 1982032041 0631432831624
C1 15-MAR-2012 09:07:26 269352960 5581790386 0113496771567
C1 31-JUL-2012 23:20:23 134676480 4799842978 0813391427349
Another thing is that, as I said above, the actual table has 120 fields. Do I have to list them all manually if I use something similar?If that's what you need, then yes you would have to list them. You only get data if you tell it you want it. ;)
Of course if you are taking the start_date_of_call, callingnumber and callednumber as the 'key' to the record, then you could join the results of the above back to the original table1 and pull out the rest of the columns that way...
SQL> select * from table1;
SEGMENTID START_DATE_OF_CALL DURATION CALLINGNUMBER CALLEDNUMBER COL1 COL2 COL3
C1 31-JUL-2012 23:20:23 134676480 4799842978 0813391427349 556 40 5.32
C21 15-MAR-2012 09:07:26 134676480 5581790386 0113496771567 219 100 10.16
C23 11-MAY-2012 09:37:26 134676480 5581790386 0113496771567 321 73 2.71
C21 11-MAY-2012 12:13:10 3892379648 1982032041 0631432831624 959 80 2.87
C22 11-MAY-2012 12:43:10 3892379648 1982032041 0631432831624 375 57 8.91
C22 11-MAY-2012 13:13:10 117899264 1982032041 0631432831624 778 27 1.42
C23 11-MAY-2012 13:43:10 117899264 1982032041 0631432831624 308 97 3.26
7 rows selected.
SQL> ed
Wrote file afiedt.buf
1 with t2 as (
2 select 'C1' as segmentid
3 ,start_date_of_call, duration, callingnumber, callednumber
4 from (
5 select distinct
6 min(start_date_of_call) over (partition by callingnumber, callednumber) as start_date_of_call
7 ,sum(duration) over (partition by callingnumber, callednumber) as duration
8 ,callingnumber
9 ,callednumber
10 from table1
11 )
12 )
13 --
14 select t2.segmentid, t2.start_date_of_call, t2.duration, t2.callingnumber, t2.callednumber
15 ,t1.col1, t1.col2, t1.col3
16 from t2
17 join table1 t1 on ( t1.start_date_of_call = t2.start_date_of_call
18 and t1.callingnumber = t2.callingnumber
19 and t1.callednumber = t2.callednumber
20* )
SQL> /
SEGMENTID START_DATE_OF_CALL DURATION CALLINGNUMBER CALLEDNUMBER COL1 COL2 COL3
C1 11-MAY-2012 12:13:10 8020557824 1982032041 0631432831624 959 80 2.87
C1 15-MAR-2012 09:07:26 269352960 5581790386 0113496771567 219 100 10.16
C1 31-JUL-2012 23:20:23 134676480 4799842978 0813391427349 556 40 5.32
SQL>Of course this is pulling back the additional columns for the record that matches the start_date_of_call for that calling/called number pair, so if the values differed from row to row within the calling/called number pair you may need to aggregate those (take the minimum/maximum etc. as required) as part of the first query. If the values are known to be the same across all records in the group then you can just pick them up from the join to the original table as I coded in the above example (only in my example the data was different across all rows).
Maybe you are looking for
-
I have around 2,000 pictures in my camera roll and around 4-5 albums. Before, all my pictures were sorted alphabetically, but after this upgrade each album's pictures seem to be in a random order. Any ideas on how to order them the same way they ar
-
User Exit or BADI for Material,BOM,Customer,Vendor
Dear All, I have requirement where if User A changes a Material X .It should go for approval by workflow. When the Material X is waiting for approval no other User should be able to change the material .It should give him a message and restrict him f
-
Unable to get phone line working - next appointmen...
Hi I moved home a few day before Christmas and the phone and broadband were due to be activated on the 7th January which was fully understandable. Nothing happened on that day so after calling the helpdesk I was told it should be done on the 9th. On
-
Gmail not working on Ipad/Iphone but works on Mac
I am having problems with a gmail on my Ipad and Iphone when i try to send an email I get the following error "Cannot send mail ,the user name or password for gmail is incorrect" I have checked and the username and password are correct The strange pa
-
What kind of HP-Printer I should buy to be able to print A3 ART-Print and Photo and Canvas?
Hi I am painting and drawing my art yet I would like to know if there is some Hp model printer which I could use to reproduce my A3 or A2 prints at home instead of leaving for others to do so. I am interesting Glicee print...yet big vide machines are