Index statistics update

30 views
Skip to first unread message

Ertan Küçükoglu

unread,
Jul 2, 2025, 6:44:21 AM7/2/25
to firebird...@googlegroups.com
Hello,

I am using FirebirdSQL 5 latest.
I found the script below and have been using it for a while.
I just started to wonder if it needs to be run in a transaction and if that transaction needs to be committed.

  SET TERM ^ ;
  EXECUTE BLOCK
  AS
  DECLARE INDEX_NAME VARCHAR(63);
  BEGIN
    FOR SELECT RDB$INDEX_NAME FROM RDB$INDICES WHERE RDB$SYSTEM_FLAG=0 INTO :INDEX_NAME DO
      EXECUTE STATEMENT 'SET STATISTICS INDEX ' || '"' || :INDEX_NAME || '"' || ';';
  END^
  SET TERM ; ^


Thanks & Regards,
Ertan

Dimitry Sibiryakov

unread,
Jul 2, 2025, 6:47:03 AM7/2/25
to firebird...@googlegroups.com
Ertan Küçükoglu wrote 02.07.2025 12:44:
> I just started to wonder if it needs to be run in a transaction and if that
> transaction needs to be committed.

(Almost) no statement in Firebird can be executed outside of transaction.

Yes, real statistic update happen only on commit.

--
WBR, SD.

Mark Rotteveel

unread,
Jul 2, 2025, 7:03:34 AM7/2/25
to firebird...@googlegroups.com
Almost everything you execute in Firebird requires a transaction, and
you should end transactions as soon as you're done. Given this modifies
information in the system tables, I think you'll need to end with a
commit, I think (though I haven't verified if a rollback would retain
the modified statistics, I would be surprised if it did).

Mark
--
Mark Rotteveel
Reply all
Reply to author
Forward
0 new messages