Subject RE: [firebird-support] mon$statement_id is not consistent between snapshots?
Author Leyne, Sean
Douglas,

> Playing with the monitoring tables I just noticed that the same
statement
> can have different ids on different snapshots. Why is that?
>
> Example:
> Connection A issues
> select count(*) from table
>
> Now suppose that this table is really big and counting takes a long
time.
> While connection A is counting records, connection B issues
> select * from mon$statements where mon$attachment_id <>
current_connection
>
> at this point the count statement has id 20.
> A bit later, the count finishes and connection B issues the same
select on
> mon$statements, but now the id is 22.
>
> Is that expected behaviour? That the same statement can show different
ids
> on different snapshots?

You are making the assumption that the SQL text is what identifies a
unique statement -- that has never been the case.

From the engine perspective it is how the SQL Text is handled by the
client which allows for the re-use of the statement handle. This is
done by the client PREPARING the statement, and then invoking the
command using the statement handle.

PREPARING statement not something which is usually done by interactive
database tools, most simply EXECUTE the SQL.

> If so, any suggestion how can I uniquely identify a statement?

Why do you want to do this?

The explanation will help in understanding how this could be done --
there is no direct way.


Sean