Skip to content

Commit

Permalink
Change the behaviour of the statistics functions. emaj_log_stat_group…
Browse files Browse the repository at this point in the history
…() and emaj_detailed_log_stat_group() now return begin and end marks name and timestamp. They also filter tables that belonged to the group during the period framed by the supplied first and last marks (and not only tables belonging to the group at the function execution time). Tables that have been removed during this time frame is reported with a counter representing the row changes for the period when the table belonged to the group. The report is not ordered by schema and table names, not taking into account the priority anymore. Create an additional index on emaj_mark to speedup statistics functions when there are a lot of marks. Delete from the documentation the exemple using the emaj_detailled_log_stat_group() function to get statistics for a single table.
  • Loading branch information
beaud76 committed Feb 1, 2018
1 parent 20f766a commit b2a3e30
Show file tree
Hide file tree
Showing 56 changed files with 2,290 additions and 1,634 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ E-Maj - Change log
<NEXT_VERSION>
------
###Enhancements:###

* Change the behaviour of the statistics functions. emaj_log_stat_group()
and emaj_detailed_log_stat_group() now return begin and end marks name
and timestamp. They also filter tables that belonged to the group during
the period framed by the supplied first and last marks (and not only
tables belonging to the group at the function execution time).

###Bug fixes:###

Expand Down
84 changes: 45 additions & 39 deletions docs/en/statFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@ Full global statistics about logs content are available with this SQL statement:

The function returns a set of rows, whose type is named *emaj.emaj_log_stat_type*, and contains the following columns:

+--------------+--------+-------------------------------------------------------+
| Column | Type | Description |
+==============+========+=======================================================+
| stat_group | TEXT | tables group name |
+--------------+--------+-------------------------------------------------------+
| stat_schema | TEXT | schema name |
+--------------+--------+-------------------------------------------------------+
| stat_table | TEXT | table name |
+--------------+--------+-------------------------------------------------------+
| stat_rows | BIGINT | number of updates recorded into the related log table |
+--------------+--------+-------------------------------------------------------+
+--------------------------+-------------+-------------------------------------------------------+
| Column | Type | Description |
+==========================+=============+=======================================================+
| stat_group | TEXT | tables group name |
+--------------------------+-------------+-------------------------------------------------------+
| stat_schema | TEXT | schema name |
+--------------------------+-------------+-------------------------------------------------------+
| stat_table | TEXT | table name |
+--------------------------+-------------+-------------------------------------------------------+
| stat_first_mark | TEXT | mark name of the period start |
+--------------------------+-------------+-------------------------------------------------------+
| stat_first_mark_datetime | TIMESTAMPTZ | mark timestamp of the period start |
+--------------------------+-------------+-------------------------------------------------------+
| stat_last_mark | TEXT | mark name of the period end |
+--------------------------+-------------+-------------------------------------------------------+
| stat_last_mark_datetime | TIMESTAMPTZ | mark timestamp of the period end |
+--------------------------+-------------+-------------------------------------------------------+
| stat_rows | BIGINT | number of updates recorded into the related log table |
+--------------------------+-------------+-------------------------------------------------------+

A *NULL* value or an empty string ('') supplied as start mark represents the oldest mark.

Expand All @@ -41,6 +49,8 @@ The keyword *'EMAJ_LAST_MARK'* can be used as mark name. It then represents the

The function returns one row per table, even if there is no logged update for this table. In this case, stat_rows columns value is 0.

Most of the time, the *stat_first_mark*, *stat_first_mark_datetime*, *stat_last_mark* and *stat_last_mark_datetime* columns reference the start and end marks of the requested period. But they can contain other values when a table has been added or removed from the tables group during the requested time interval.

It is possible to easily execute more precise requests on these statistics. For instance, it is possible to get the number of database updates by application schema, with a statement like:

.. code-block:: sql
Expand Down Expand Up @@ -68,21 +78,29 @@ Scanning log tables brings a more detailed information, at a higher response tim

The function returns a set of rows, whose type is named *emaj.emaj_detailed_log_stat_type*, and contains the following columns:

+--------------+-------------+--------------------------------------------------------------------------------------------------+
| Column | Type | Description |
+==============+=============+==================================================================================================+
| stat_group | TEXT | tables group name |
+--------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_schema | TEXT | schema name |
+--------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_table | TEXT | table name |
+--------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_role | VARCHAR(32) | connection role |
+--------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_verb | VARCHAR(6) | type of the SQL verb that has performed the update, with values: *INSERT* / *UPDATE* / *DELETE*) |
+--------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_rows | BIGINT | number of updates recorded into the related log table |
+--------------+-------------+--------------------------------------------------------------------------------------------------+
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| Column | Type | Description |
+==========================+=============+==================================================================================================+
| stat_group | TEXT | tables group name |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_schema | TEXT | schema name |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_table | TEXT | table name |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_first_mark | TEXT | mark name of the period start |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_first_mark_datetime | TIMESTAMPTZ | mark timestamp of the period start |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_last_mark | TEXT | mark name of the period end |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_last_mark_datetime | TIMESTAMPTZ | mark timestamp of the period end |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_role | VARCHAR(32) | connection role |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_verb | VARCHAR(6) | type of the SQL verb that has performed the update, with values: *INSERT* / *UPDATE* / *DELETE*) |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+
| stat_rows | BIGINT | number of updates recorded into the related log table |
+--------------------------+-------------+--------------------------------------------------------------------------------------------------+

A *NULL* value or an empty string ('') supplied as start mark represents the oldest mark.

Expand All @@ -92,19 +110,7 @@ The keyword *'EMAJ_LAST_MARK'* can be used as mark name. It then represents the

Unlike :ref:`emaj_log_stat_group() <emaj_log_stat_group>`, the *emaj_detailed_log_stat_group()* function doesn't return any rows for tables having no logged updates inside the requested marks range. So *stat_rows* column never contains 0.

It is possible to easily execute more precise requests on these statistics. For instance, it is possible to get the number of updates for a given table, here *mytbl1*, per SQL verb, using a statement like:

.. code-block:: sql
postgres=# SELECT stat_table, stat_verb, stat_rows
FROM emaj.emaj_detailed_log_stat_group('myAppl1', NULL, NULL)
WHERE stat_table='mytbl1';
stat_table | stat_verb | stat_rows
------------+-----------+-----------
mytbl1 | DELETE | 1
mytbl1 | INSERT | 6
mytbl1 | UPDATE | 2
(3 rows)
Most of the time, the *stat_first_mark*, *stat_first_mark_datetime*, *stat_last_mark* and *stat_last_mark_datetime* columns reference the start and end marks of the requested period. But they can contain other values when a table has been added or removed from the tables group during the requested time interval.

.. _emaj_estimate_rollback_group:

Expand Down

0 comments on commit b2a3e30

Please sign in to comment.