Subject | Re: [firebird-support] How To Speed Up Update SQL |
---|---|
Author | Vishal Tiwari |
Post date | 2015-10-15T07:44:51Z |
Yesssssssss..........................
YOU ROCKS SET AS USUAL...... WORKING ABSOLUTELY FINE........
Five Stars from my side. *****
You know what I tried with Merge statement as well and that is also fine...
merge into MY_BOOK MB
using MY_BOOK_HEADER MBH
on (MB.SK_BOOK_HEADER = MBH.PK_BOOK_HEADER and
MB.BOOK_TYPE = 4 and
MBH.HEADER_BOOK_CODE = '127518010109038' and
MBH.FK_BOOK_GROUP = '{79B79C33-CE56-4084-912B-6DD9F70B3DC4}')
when matched then
update set
MB.BOOK_NAME = 'Book Name1',
MB.BOOK_DESCRIPTION = 'Book Desfcription1';
By the way, you always write HTH, at the end of mail. What does it stands for ? Just for curiosity asking.
On Thursday, 15 October 2015 11:46 AM, "Vishal Tiwari vishualsoft@... [firebird-support]" <firebird-support@yahoogroups.com> wrote:
HI SET,
PK is GUID type.
On Wednesday, 14 October 2015 10:51 PM, "setysvar setysvar@... [firebird-support]" <firebird-support@yahoogroups.com> wrote:
so I could learn from it.>>1. EXECUTE BLOCK and there for select and delete
>I am completely unaware about execute block. Would you offer any help,
If PK is your integer primary key for MY_BOOK, then you should be able
to do something like this:
execute block returns(Changes integer) as
declare variable mbPK integer;
begin
Changes = 0;
for select distinct MB.PK
from MY_BOOK MB
join MY_BOOK_HEADER MBH on MBH.PK_BOOK_HEADER = MB.SK_BOOK_HEADER
where MB.BOOK_TYPE = 4
and Upper(Trim(MBH.HEADER_BOOK_CODE)) = Upper(Trim('127518010109038'))
--UPPER and TRIM doesn't make any difference to a constant containing
only digits and no whitespace...
And MBH.FK_BOOK_GROUP = '{79B79C33-CE56-4084-912B-6DD9F70B3DC4}'
into :mbPK do
begin
update My_Book SET BOOK_NAME = 'Book Name1', BOOK_DESCRIPTION =
'Book Description1'
where PK = :mbPK;
Changes = Changes + ROW_COUNT;
end
suspend;
end
'Changes' and 'suspend' is not required, but whenever I use EXECUTE
BLOCK myself, I prefer to add such a variable to ascertain that I only
update the ten records I want to update and not one million due to
forgetting something important in the JOIN or WHERE clauses.
I think execute block can particularly improve performance if
a) You only want to reduce a small fraction of the records in My_Book,
and/or
b) the EXISTS clause is complicated and time consuming
If both My_Book and My_Book_Header are small tables with sensible
indexing, using execute block may be of little or no help.
HTH,
Set