SQL query progress using PostgreSQL or My SQL

Introduction

Welcome all. When working on web application management, I often encounter a problem that I have never solved with my current knowledge. In my applications, most data retrieval processes are long-lived due to complex queries and large amounts of data. In fact, the latency for retrieving data through PHP is largely consumed by QUERY EXECUTION (in most cases). Suppose we have this general situation.

enter image description here

Question

At this point, my question is: is there a solution in order to find out at what point in the query execution process arrived, and then trace the request for my [PROGRESS QUERY%]?

My decision

So far, the solution I have used is the following: "Request Time History"

, , , . , , , , , , , [ QUERY%].

: ( )

HTML

<!-- where "data-seconds" are the average seconds of the execution saved in my query time history table -->
<button type="button" id="runQuery" data-seconds="500">Get Data</button>    
<div class="progress">
  <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%">
  </div>
</div>

JAVASCRIPT

$("#runQuery").on("click", function() {
    var currentSeconds = 0;
    var totalSeconds = parseFloat($(this).data("seconds"));
    var $progressBar = $(".progress-bar");
    var progressPercentage = 0;
    var execution;

    $.ajax({
        url: "scriptForQueryExecution.php", type: "POST", beforeSend: function() {
            execution = setInterval(function() {
                progressPercentage = currentSeconds / totalSeconds * 100;
                $progressBar.css("width", progressPercentage + '%').attr("aria-valuenow", progressPercentage);

                currentSeconds++;
            }, 1000);
        }, success: function() {
            $progressBar.css("width", '100%').attr("aria-valuenow", 100);
            clearInterval(execution);
        }
    });
});
+4
2

MariaDB " " SHOW PROCESSLIST INFORMATION_SCHEMA.PROCESSLIST, 5 ( ). : https://mariadb.com/kb/en/library/progress-reporting/.

PostgreSQL , VACUUM: https://www.postgresql.org/docs/9.6/static/progress-reporting.html

, , XHR CSS.

+2

, , , , , select count([ID]) from dbo.MyTable, 1 , , , ...

+1

Source: https://habr.com/ru/post/1689467/


All Articles