'H2 Database - What does SELECTIVITY mean in ERROR messages

I'm using H2 for java unit tests. When intentionally invoking an error by inserting a value that is too large I see 2 different responses from H2:

 Value too long for column "MY_COLUMN VARCHAR(50)"

and

 Value too long for column "MY_COLUMN VARCHAR(50) SELECTIVITY 20"

What I am trying to understand why and what "SELECTIVITY" means in this case. Is there something I can do to get a consistent response I can assert on besides the obvious workarounds like using "StartsWith"?



Solution 1:[1]

You might have figured it out by now, but I came across this question and others might come here, too:

SELECTIVITY is part of the column definition. From the H2 documentation:

The selectivity describes the 'uniqueness' of values in a column. A selectivity of 100 means each value appears only once, and a selectivity of 1 means the same value appears in many or most rows.

H2 can only use one index per table1, however, if multiple indices could be used for a query, then the selectivity decides which index is used.

So, in your case, it looks as if the column definition changes in between unit tests. This could be the case if, e.g, you have setup a memory database that is being recreated for each test.


1 The documentation here states one index per join, but if you don't have any joins it is just one index for the table

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 moonlight