Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2056

Limit/Offset in generated Sql does not work for many databases

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      SqlDialect.supportsOffsetFetch() defines whether the dialect supports OFFSET/FETCH clauses introduced by SQL:2008, and by default returns true.
      SqlPrettyWriter.fetchOffset(SqlNode, SqlNode) uses that information to insert "FETCH NEXT x ROWS" if it supportsOffsetFetch.
      However, I noticed that many of the databases support it in different ways and some do not support at all.
      For example, Hsqldb, which is used in test cases does not accept FETCH NEXT x ROWS, but it accepts LIMIT and FETCH FIRST x ROWS.
      Some databases accept TOP x and others use something even different, but most of them also accept LIMIT syntax.
      I suggest we make using LIMIT the default, because it is the most accepted and allow each SqlDialect do define its own way of using fetch and offset.
      If we check how Hibernate sets the dialects to deal with limit/offset for each database, we see that most use limit syntax and some use special syntax, but very few are configured to use SQL 2008 syntax.
      This hasn't been a problem until now because sort/limit/offset was not being pushed to the database. But now that I'm trying to fix it, the generated SQL is not working in Hsqldb.

      Attachments

        Activity

          People

            Unassigned Unassigned
            lfkauer Luis Fernando Kauer
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: