Skip to content

Make NULLs comparable to everything.#8834

Merged
alexey-milovidov merged 3 commits intoClickHouse:masterfrom
zlobober:comparable_nulls
Jan 28, 2020
Merged

Make NULLs comparable to everything.#8834
alexey-milovidov merged 3 commits intoClickHouse:masterfrom
zlobober:comparable_nulls

Conversation

@zlobober
Copy link
Copy Markdown
Contributor

@zlobober zlobober commented Jan 25, 2020

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

In this PR we make NULL fields comparable to any other fields. Default comparison order is similar to NULLS_LAST, but it may be overridden during linkage by rewriting extern const bool DB::NULLS_LAST weak symbol.

This is important to third-party applications using ClickHouse as a library which rely on DB::KeyCondition in order to prune input possibly containing NULLs.

Changelog category (leave one):

  • Non-significant (changelog entry is not required)

Related: #5319

@alexey-milovidov
Copy link
Copy Markdown
Member

it may be overridden during linkage by rewriting extern const bool DB::NULLS_LAST weak symbol

If it is unused right now, better not introduce this tweak at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also look at line 342, maybe it was incorrect.

template <typename T>
bool operator() (const Null &, const T &) const

Copy link
Copy Markdown
Contributor Author

@zlobober zlobober Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I forgot about this method, thanks.

Copy link
Copy Markdown
Contributor Author

@zlobober zlobober left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed introduction of weak symbol NULLS_LAST internally with @alexey-milovidov and decided to continue with NULLS_FIRST comparison here without any possible customization.

@zlobober
Copy link
Copy Markdown
Contributor Author

@alexey-milovidov, would you mind checking again?

return l < r;
else if constexpr (std::is_same_v<U, Int64> || std::is_same_v<U, UInt64>)
return l < DecimalField<Decimal128>(r, 0);
if constexpr (std::is_same_v<T, Null>)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks wrong.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:( You are right, I misinterpreted the meaning of T.

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@alexey-milovidov
Copy link
Copy Markdown
Member

Request for the next PR:

  • add a setting allow_nullable_key, false by default;
  • if it is set or if we attach table, allow Nullable key;
  • add a test where comparison with null is covered.

@zlobober
Copy link
Copy Markdown
Contributor Author

One more attempt.

@alexey-milovidov alexey-milovidov merged commit 30c1147 into ClickHouse:master Jan 28, 2020
@calebeaires
Copy link
Copy Markdown

Hey @alexey-milovidov, is your solution implemented? If so, who take it on the instance!?

@amosbird
Copy link
Copy Markdown
Collaborator

It seems nullable keys are valid after this pr. I'll help finish what @alexey-milovidov proposed

@alexey-milovidov
Copy link
Copy Markdown
Member

Ok. And please add a setting to alllow/disallow Nullable in primary key, because allowing them contradicts with SQL standard or usual behaviour of other DBMS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants