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

> Playing with the monitoring tables I just noticed that the same
> 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
> While connection A is counting records, connection B issues
> select * from mon$statements where mon$attachment_id <>
> 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
> 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.