.. _version_5.1.1:

=============
Version 5.1.1
=============

Released on 2022-11-09.

.. NOTE::

    If you are upgrading a cluster, you must be running CrateDB 4.0.2 or higher
    before you upgrade to 5.1.1.

    We recommend that you upgrade to the latest 5.0 release before moving to
    5.1.1.

    A rolling upgrade from 5.0.x to 5.1.1 is supported.
    Before upgrading, you should `back up your data`_.

.. WARNING::

    Tables that were created before CrateDB 4.x will not function with 5.x
    and must be recreated before moving to 5.x.x.

    You can recreate tables using ``COPY TO`` and ``COPY FROM`` or by
    `inserting the data into a new table`_.

.. _back up your data: https://crate.io/docs/crate/reference/en/latest/admin/snapshots.html
.. _inserting the data into a new table: https://crate.io/docs/crate/reference/en/latest/admin/system-information.html#tables-need-to-be-recreated



.. rubric:: Table of Contents

.. contents::
   :local:

See the :ref:`version_5.1.0` release notes for a full list of changes in the
5.1 series.

Fixes
=====

- Fixed an issue that prevented ``_id IN (SELECT ...)`` from matching records.

- Fixed an issue that could lead to a ``class_cast_exception`` error when using
  ``ORDER BY`` on a column of type ``TEXT`` or ``VARCHAR``.

- Changed the logic to resolve functions. Previously it would first look for
  built-ins for all schemas within the search path before looking up user
  defined functions. Now it will search for built-in and UDF per schema to
  prioritize UDFs earlier in the search path over built-ins later in the search
  path.

- Fixed an issue that could lead to a encoded value getting returned for ``bit``
  columns that are part of an ``object`` column.

- Fixed an issue that caused incorrect results to be returned when using
  :ref:`array(subquery) <scalar-array>` when the subquery is using ``ORDER BY``
  on a different column than the one returned, i.e.::

    SELECT array(SELECT country FROM sys.summits ORDER BY height DESC LIMIT 3)

- Fixed an issue that prevented defining a ``bit`` column with the same name as
  the parent object within a table. i.e.::

    CREATE TABLE tbl (x OBJECT AS (x bit(1)))
                      ^            ^

- Fixed an issue that could lead to out of memory errors if using the
  ``percentile`` aggregation.

- Fixed an issue that could lead to serialization errors when using the ``bit``
  type in objects.

- Fixed an issue that could lead to ``IllegalIndexShardStateException`` errors
  when running a ``SELECT count(*) FROM tbl`` on partitioned tables.

- Fixed an issue which caused ``PRIMARY KEY`` columns to be required on insert
  even if they are generated and their source columns are default not-null,
  i.e.::

    CREATE TABLE test (
      id INT NOT NULL PRIMARY KEY,
      created TIMESTAMP WITH TIME ZONE DEFAULT current_timestamp NOT NULL,
      month TIMESTAMP GENERATED ALWAYS AS date_trunc('month', created) PRIMARY KEY
    );

    INSERT INTO test(id) VALUES(1);

- Fixed an issue that could cause ``COPY FROM``, ``INSERT INTO``,
  ``UPDATE`` and ``DELETE`` operations to get stuck if under memory pressure.

- Fixed an issue that didn't allow queries with a greater than ``0`` ``OFFSET``
  but without ``LIMIT`` to be executed successfully, i.e.::

    SELECT * FROM test OFFSET 10
    SELECT * FROM test LIMIT null OFFSET 10
    SELECT * FROM test LIMIT ALL OFFSET 10

- Fixed an issue that caused ``col IS NULL`` to match empty objects.

- Fixed an issue that caused ``ARRAY_COL = []`` to throw an exception on
  ``OBJECT``, ``GEO_SHAPE``, ``IP`` or ``BIT`` array element types.

- Fixed an issue that caused queries reading values of type ``BIT`` to return a
  wrong result if the query contains a ``WHERE`` clause ``pk_col = ?``
  condition.

- Fixed an issue that prevented ``NOT NULL`` constraints on ``GEO_SHAPE``
  columns from showing up in ``SHOW CREATE TABLE`` statements.
