1
UPDATE TABLE SET SOMETHING = 1 WHERE ID IN (SELECT ID FROM STORED_PROCEDURE)

Records in TABLE = 2100

Records from stored procedure = 50

This statement cousing enormous amount of fetches (31M!) on firebird 2.5 server. Why? Shouldn't it first select id's from stored procedure and then put it in where clause? What should I do to make it work?

8
  • @JustMe: Is STORED_PROCEDURE a table or a function, and if the latter what's the procedure doing in terms of database access? Apr 20, 2011 at 11:52
  • @Bob It's a selectable stored procedure - one "for select" with suspend
    – JustMe
    Apr 20, 2011 at 12:20
  • @JustMe: OK - and what does the stored procedure do in terms of database access? Apr 20, 2011 at 13:35
  • @Bob It is selecting rows from database (select from table) - operating on the same table as UPDATE
    – JustMe
    Apr 20, 2011 at 13:50
  • @Bob Just try to do SELECT ... WHERE ID IN (STORED_PROCEDURE) - You'll see the problem. It fetches stored procedure for all record in select table and then cut it in where clause
    – JustMe
    Apr 20, 2011 at 15:57

1 Answer 1

1

Try something like this:

declare variable myid integer;    
begin
    for
        select id from stored_procedure into :myID
    do begin
      update table set something = 1 where table.id = :myID;
    end
end
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.