c++ - is there a way to remove the select count(*) from this sql statement and logic -
I have some C ++ code that updates the column when a row is present otherwise there is nothing here Code looks like now and the selection count (*) takes about 15-20 seconds I would like to make this code more efficient.
Runupdate Lockless Timestamp
sCommand & lt; & Lt; "Set up APCLoXX ALIVETIMESTAMP = Update"; SCommand & lt; & Lt; "SYSTIMESTAMP (7)"; SCommand & lt; & Lt; "Where TRANSACTIONID =?";
RunScheckCat accountCubblocks
sCommand & lt; & Lt; "Count (*) from APP_CC_LOCKS"; SCommand & lt; & Lt; "Where ((SCENARIOID =? And YEARID =? And ENTITYID =? And PARENTID =? And VALUEID =?) And (LOCKTYPE =?)) Or (LOCKTYPE =?)) And (transactionId! =?) And ((TIMEINSERTED & Lt; (Selection Max (TIMEINSERTED from APP_CC_LOCKS) "; sCommand
Main
DWORD dwIterationNumber = 0; // accquire lock trying cStartTime = DateTimeUtil :: currentDateTimeAsMilliseconds (); While (bLockWasAcquired == incorrect) {/ / lock numbllockingRecords = 1; Hr = cAccessor.RunSelectCountDataCubeLock (CtstransID, LScinario, Leire, Linti, Alparant, LVR, and attempt to get numbllockingRecords)); Xfm_throw_propagate (FAILED (HR), HR); // If there is no block record then lock is temporary accquir until we resolve the collision (numBlockingRecords == 0) {// Lock now bLockWasAcquired = Truth has been received; break; } If (dwIterationNumber & gt; g_lNumIterBeforeUpdatingTimeStamp) {//csSQLCmd.clear (); Hr = cAccessor.RunUpdateLockAliveTimeStamp (csTransID); Xfm_throw_Propagate (FAILED (HR), HR); }}
i dont think count (*) What query is making slow, but two sub selections
where
section
... ((TIMEINSERTED & lt inside Is being done with APP_CC_LOCKS from TRANSACTIONID =?)) Or ((TIMEINSERTED = (APP_CC_LOCKS to MAX (TIMEINSERTED where TRANSACTIONID =?))
be replaced with a single sub selection Select:
((TIMEINSERTED & LT;? = (Select MAX (TIMEINSERTED) from APP_CC_LOCKS where transactionId =))
Maybe half execution time
Comments
Post a Comment