Search code examples
databasecnosdb

How to do pagination in CnosDB?


There are some some concepts (limit/offset/slimit/soffset) in CnosDB similar to MySQL's limit/offset. I assume they could be used for pagination but I am really confused that why when I perform a query via limit 1, there are more than 1 result returned? Is this related to the series?


Solution

  • In CnosQL, you can use LIMIT\SLIMIT\OFFSET\SOFFSET in these cases:

    • LIMIT <N> returns the first N points from the specified measurement.
    • SLIMIT <N> returns every point from N series in the specified measurement.
    • OFFSET <N> paginates N points in the query results.
    • SOFFSET <N> paginates N series in the query results.

    Compared with the SQL, there are several differences between CnosQL and SQL in the syntax of LIMIT\SLIMIT\OFFSET\SOFFSET.

    In SQL, LIMIT <N> clause is used to limit the number of query results returned. It is often used for paginating queries.

    In SQL, OFFSET <N> clause is used to skip N data and return the query results. As same as LIMIT <N>, OFFSET <N> is often used for paginating queries.

    So, in order to understand the differences between CnosQL and SQL, we must make clear of some relative concept.

    CnosDB is a time series database, which means the data restored is somewhat different from SQL databases. In short, CnosDB is made to store a large volume of time-series data and perform real-time analysis on those data, quickly.

    The data in CnosDB is made up of measurement,tag,field and timestamp. Data points can have one of the fields on a measurement, all of the fields on a measurement, or any number in-between. You can understand these concepts by comparing with SQL.

    • An CnosDB measurement is similar to an SQL database table.
    • CnosDB tags are like indexed columns in an SQL database.
    • CnosDB fields are like unindexed columns in an SQL database.
    • CnosDB points are similar to SQL rows.

    There are some concepts in CnosDB similar to SQL, but there also a new concept in CnosDB, series.

    series, means a logical grouping of data defined by shared measurement, tag set, and field key.

    SQL doesn't support the SLIMIT <N> clause and SOFFSET <N> clause, because the data in SQL doesn‘t have the concept of series.

    There are many series in a CnosDB database. So the SLIMIT\SOFFSET clause is used to paginate series in result.

    Click here for more information about the CnosDB.