----------------------------------------------------------------------------------------------------------------------------------------------------------
--- HISTORY PostgreSQL -----------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------

getAggregationByIntervalFromSql():
FIRST:
SELECT h.itemid,h.value,h.clock,h.ns,s.tick
    FROM history_uint h
        JOIN (
            SELECT h2.itemid,h2.clock,MIN(h2.ns) AS ns,s2.tick
                FROM history_uint h2
                    JOIN (
                        SELECT itemid,CAST(clock AS BIGINT)-MOD(CAST(clock AS BIGINT),3600) AS tick,MIN(clock) AS clock
                            FROM history_uint
                            WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                                AND clock BETWEEN 1747723854 AND 1747810254
                            GROUP BY itemid,CAST(clock AS BIGINT)-MOD(CAST(clock AS BIGINT),3600)
                    ) s2 ON h2.itemid=s2.itemid
                        AND h2.clock=s2.clock
                WHERE h2.clock BETWEEN 1747723854 AND 1747810254
                GROUP BY h2.itemid,h2.clock,s2.tick
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
            AND h.ns=s.ns
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
Time: 4.993 ms

LAST:
SELECT h.itemid,h.value,h.clock,h.ns,s.tick
    FROM history_uint h
        JOIN (
            SELECT h2.itemid,h2.clock,MAX(h2.ns) AS ns,s2.tick
                FROM history_uint h2
                    JOIN (
                        SELECT itemid,CAST(clock AS BIGINT)-MOD(CAST(clock AS BIGINT),3600) AS tick,MAX(clock) AS clock
                            FROM history_uint
                            WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                                AND clock BETWEEN 1747723854 AND 1747810254
                            GROUP BY itemid,CAST(clock AS BIGINT)-MOD(CAST(clock AS BIGINT),3600)
                    ) s2 ON h2.itemid=s2.itemid
                        AND h2.clock=s2.clock
                WHERE h2.clock BETWEEN 1747723854 AND 1747810254
                GROUP BY h2.itemid,h2.clock,s2.tick
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
            AND h.ns=s.ns
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
Time: 5.003 ms

----------------------------------------------------------------------------------------------------------------------------------------------------------

getAggregatedValuesFromSql():
FIRST:
SELECT h.itemid,h.value,h.clock
    FROM history_uint h
        JOIN (
            SELECT h2.itemid,h2.clock,MIN(h2.ns) AS ns
                FROM history_uint h2
                    JOIN (
                        SELECT itemid,MIN(clock) AS clock
                            FROM history_uint
                            WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                                AND clock BETWEEN 1747723854 AND 1747810254
                            GROUP BY itemid
                    ) s2 ON h2.itemid=s2.itemid
                        AND h2.clock=s2.clock
                WHERE h2.clock BETWEEN 1747723854 AND 1747810254
                GROUP BY h2.itemid,h2.clock
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
            AND h.ns=s.ns
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
Time: 5.195 ms

LAST:
SELECT h.itemid,h.value,h.clock
    FROM history_uint h
        JOIN (
            SELECT h2.itemid,h2.clock,MAX(h2.ns) AS ns
                FROM history_uint h2
                    JOIN (
                        SELECT itemid,MAX(clock) AS clock
                            FROM history_uint
                            WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                                AND clock BETWEEN 1747723854 AND 1747810254
                            GROUP BY itemid
                    ) s2 ON h2.itemid=s2.itemid
                        AND h2.clock=s2.clock
                WHERE h2.clock BETWEEN 1747723854 AND 1747810254
                GROUP BY h2.itemid,h2.clock
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
            AND h.ns=s.ns
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
Time: 5.653 ms

----------------------------------------------------------------------------------------------------------------------------------------------------------
--- HISTORY MySQL ----------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------

getAggregationByIntervalFromSql():
FIRST:
SELECT sql_no_cache h.itemid,h.value,h.clock,h.ns,s.tick
    FROM history_uint h
        JOIN (
            SELECT h2.itemid,h2.clock,MIN(h2.ns) AS ns,s2.tick
                FROM history_uint h2
                    JOIN (
                        SELECT itemid,CAST(clock AS UNSIGNED)-MOD(CAST(clock AS UNSIGNED),3600) AS tick,MIN(clock) AS clock
                            FROM history_uint
                            WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                                AND clock BETWEEN 1747723854 AND 1747810254
                            GROUP BY itemid,CAST(clock AS UNSIGNED)-MOD(CAST(clock AS UNSIGNED),3600)
                    ) s2 ON h2.itemid=s2.itemid
                        AND h2.clock=s2.clock
                WHERE h2.clock BETWEEN 1747723854 AND 1747810254
                GROUP BY h2.itemid,h2.clock,s2.tick
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
            AND h.ns=s.ns
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
150 rows in set (0.014 sec)

LAST:
SELECT sql_no_cache h.itemid,h.value,h.clock,h.ns,s.tick
    FROM history_uint h
        JOIN (
            SELECT h2.itemid,h2.clock,MAX(h2.ns) AS ns,s2.tick
                FROM history_uint h2
                    JOIN (
                        SELECT itemid,CAST(clock AS UNSIGNED)-MOD(CAST(clock AS UNSIGNED),3600) AS tick,MAX(clock) AS clock
                            FROM history_uint
                            WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                                AND clock BETWEEN 1747723854 AND 1747810254
                            GROUP BY itemid,CAST(clock AS UNSIGNED)-MOD(CAST(clock AS UNSIGNED),3600)
                    ) s2 ON h2.itemid=s2.itemid
                        AND h2.clock=s2.clock
                WHERE h2.clock BETWEEN 1747723854 AND 1747810254
                GROUP BY h2.itemid,h2.clock,s2.tick
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
            AND h.ns=s.ns
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
150 rows in set (0.012 sec)

----------------------------------------------------------------------------------------------------------------------------------------------------------

getAggregatedValuesFromSql():
FIRST:
SELECT sql_no_cache h.itemid,h.value,h.clock
    FROM history_uint h
        JOIN (
            SELECT h2.itemid,h2.clock,MIN(h2.ns) AS ns
                FROM history_uint h2
                    JOIN (
                        SELECT itemid,MIN(clock) AS clock
                            FROM history_uint
                            WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                                AND clock BETWEEN 1747723854 AND 1747810254
                            GROUP BY itemid
                    ) s2 ON h2.itemid=s2.itemid
                        AND h2.clock=s2.clock
                WHERE h2.clock BETWEEN 1747723854 AND 1747810254
                GROUP BY h2.itemid,h2.clock
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
            AND h.ns=s.ns
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
6 rows in set (0.008 sec)

LAST:
SELECT sql_no_cache h.itemid,h.value,h.clock
    FROM history_uint h
        JOIN (
            SELECT h2.itemid,h2.clock,MAX(h2.ns) AS ns
                FROM history_uint h2
                    JOIN (
                        SELECT itemid,MAX(clock) AS clock
                            FROM history_uint
                            WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                                AND clock BETWEEN 1747723854 AND 1747810254
                            GROUP BY itemid
                    ) s2 ON h2.itemid=s2.itemid
                        AND h2.clock=s2.clock
                WHERE h2.clock BETWEEN 1747723854 AND 1747810254
                GROUP BY h2.itemid,h2.clock
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
            AND h.ns=s.ns
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
6 rows in set (0.009 sec)

----------------------------------------------------------------------------------------------------------------------------------------------------------
--- TRENDS PostgreSQL ------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------

getAggregationByIntervalFromSql():
FIRST:
SELECT DISTINCT h.itemid,h.value_avg AS value,h.clock,0 AS ns,s.tick
    FROM trends_uint h
        JOIN (
            SELECT itemid,CAST(clock AS BIGINT)-MOD(CAST(clock AS BIGINT),3600) AS tick,MIN(clock) AS clock
                FROM trends_uint
                WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                    AND clock BETWEEN 1747723854 AND 1747810254
                GROUP BY itemid,CAST(clock AS BIGINT)-MOD(CAST(clock AS BIGINT),3600)
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
Time: 5.314 ms

LAST:
SELECT DISTINCT h.itemid,h.value_avg AS value,h.clock,0 AS ns,s.tick
    FROM trends_uint h
        JOIN (
            SELECT itemid,CAST(clock AS BIGINT)-MOD(CAST(clock AS BIGINT),3600) AS tick,MAX(clock) AS clock
                FROM trends_uint
                WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                    AND clock BETWEEN 1747723854 AND 1747810254
                GROUP BY itemid,CAST(clock AS BIGINT)-MOD(CAST(clock AS BIGINT),3600)
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
Time: 4.795 ms

----------------------------------------------------------------------------------------------------------------------------------------------------------
getAggregatedValuesFromSql():
FIRST:
SELECT DISTINCT h.itemid,h.value_avg AS value,h.clock
    FROM trends_uint h
        JOIN (
            SELECT itemid,MIN(clock) AS clock
                FROM trends_uint
                WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                    AND clock BETWEEN 1747723854 AND 1747810254
                GROUP BY itemid
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
Time: 3.908 ms

LAST:
SELECT DISTINCT h.itemid,h.value_avg AS value,h.clock
    FROM trends_uint h
        JOIN (
            SELECT itemid,MAX(clock) AS clock
                FROM trends_uint
                WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                    AND clock BETWEEN 1747723854 AND 1747810254
                GROUP BY itemid
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
Time: 2.753 ms

----------------------------------------------------------------------------------------------------------------------------------------------------------
--- TRENDS MySQL -----------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------

getAggregationByIntervalFromSql():
FIRST:
SELECT sql_no_cache DISTINCT h.itemid,h.value_avg AS value,h.clock,0 AS ns,s.tick
    FROM trends_uint h
        JOIN (
            SELECT itemid,CAST(clock AS UNSIGNED)-MOD(CAST(clock AS UNSIGNED),3600) AS tick,MIN(clock) AS clock
                FROM trends_uint
                WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                    AND clock BETWEEN 1747723854 AND 1747810254
                GROUP BY itemid,CAST(clock AS UNSIGNED)-MOD(CAST(clock AS UNSIGNED),3600)
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
144 rows in set (0.003 sec)

LAST:
SELECT sql_no_cache DISTINCT h.itemid,h.value_avg AS value,h.clock,0 AS ns,s.tick
    FROM trends_uint h
        JOIN (
            SELECT itemid,CAST(clock AS UNSIGNED)-MOD(CAST(clock AS UNSIGNED),3600) AS tick,MAX(clock) AS clock
                FROM trends_uint
                WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                    AND clock BETWEEN 1747723854 AND 1747810254
                GROUP BY itemid,CAST(clock AS UNSIGNED)-MOD(CAST(clock AS UNSIGNED),3600)
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
144 rows in set (0.003 sec)

----------------------------------------------------------------------------------------------------------------------------------------------------------
getAggregatedValuesFromSql():
FIRST:
SELECT sql_no_cache DISTINCT h.itemid,h.value_avg AS value,h.clock
    FROM trends_uint h
        JOIN (
            SELECT itemid,MIN(clock) AS clock
                FROM trends_uint
                WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                    AND clock BETWEEN 1747723854 AND 1747810254
                GROUP BY itemid
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
6 rows in set (0.001 sec)

LAST:
SELECT sql_no_cache DISTINCT h.itemid,h.value_avg AS value,h.clock
    FROM trends_uint h
        JOIN (
            SELECT itemid,MAX(clock) AS clock
                FROM trends_uint
                WHERE itemid IN (163232,163273,235282,235323,626120,626164)
                    AND clock BETWEEN 1747723854 AND 1747810254
                GROUP BY itemid
        ) s ON h.itemid=s.itemid
            AND h.clock=s.clock
    WHERE h.clock BETWEEN 1747723854 AND 1747810254;
6 rows in set (0.001 sec)