Add debug queries to 03212_variant_dynamic_cast_or_default by zlareb1 · Pull Request #88269 · ClickHouse/ClickHouse · GitHub
Skip to content

Add debug queries to 03212_variant_dynamic_cast_or_default#88269

Merged
fm4v merged 9 commits into
ClickHouse:masterfrom
zlareb1:fix/03212_variant_dynamic_cast_or_default
Nov 9, 2025
Merged

Add debug queries to 03212_variant_dynamic_cast_or_default#88269
fm4v merged 9 commits into
ClickHouse:masterfrom
zlareb1:fix/03212_variant_dynamic_cast_or_default

Conversation

@zlareb1

@zlareb1 zlareb1 commented Oct 8, 2025

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Details

Added debug output to 03212_variant_dynamic_cast_or_default.sql for IPv4/IPv6 anomaly diagnostics.
No effect on normal runs.

Changes

  • Added id UInt64 DEFAULT generateSerialID('03212_variant_seq') with ENGINE = MergeTree ORDER BY id.
  • Updated inserts to INSERT INTO t (d) VALUES (...); to auto-fill id.
  • Added two debug queries (ch_dbg_summary, ch_dbg_offenders) that print only on anomaly.
  • Added helper SELECT d FROM t ORDER BY id for quick inspection.

@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 8, 2025
@Avogar Avogar self-assigned this Oct 9, 2025
@alexey-milovidov

Copy link
Copy Markdown
Member

My current hypothesis is that this behavior might be due to toIPv4OrDefault() / toIPv6OrDefault() reading from non–null-terminated buffers when operating on Dynamic values backed by FixedString.

This means they have a bug that must be fixed.

@zlareb1

zlareb1 commented Oct 9, 2025

Copy link
Copy Markdown
Member Author

My current hypothesis is that this behavior might be due to toIPv4OrDefault() / toIPv6OrDefault() reading from non–null-terminated buffers when operating on Dynamic values backed by FixedString.

This means they have a bug that must be fixed.

This may also result from certain settings combinations I am testing out to reproduce locally.

@zlareb1

zlareb1 commented Oct 9, 2025

Copy link
Copy Markdown
Member Author

The bug doesn't occur on the local machine, even without this change. I tested running the test 1000 times with different settings similar to those in failed CI jobs. The issue might be related to other factors such as architecture, OS, etc.

@zlareb1 zlareb1 force-pushed the fix/03212_variant_dynamic_cast_or_default branch 3 times, most recently from 2425805 to e75c54c Compare October 13, 2025 04:53
@zlareb1 zlareb1 changed the title Fix flaky 03212_variant_dynamic_cast_or_default test (use toString() for IP conversions) WIP: Fix flaky 03212_variant_dynamic_cast_or_default test (use toString() for IP conversions) Oct 13, 2025
@zlareb1 zlareb1 marked this pull request as draft October 15, 2025 06:34
@fm4v

fm4v commented Nov 3, 2025

Copy link
Copy Markdown
Member

Simplify test, add debug information: select * from affected table to see original values

@fm4v fm4v self-assigned this Nov 3, 2025
@zlareb1 zlareb1 force-pushed the fix/03212_variant_dynamic_cast_or_default branch 2 times, most recently from 9e2f52c to ca97849 Compare November 6, 2025 13:00
@zlareb1 zlareb1 changed the title WIP: Fix flaky 03212_variant_dynamic_cast_or_default test (use toString() for IP conversions) Add debug queries to 03212_variant_dynamic_cast_or_default Nov 6, 2025
@zlareb1

zlareb1 commented Nov 7, 2025

Copy link
Copy Markdown
Member Author

Flaky test 01872_functions_to_subcolumns_analyzer failure unrelated to this PR in https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=88269&sha=85c240b66a1e61a1f09d136c14e58451803b04f4&name_0=PR

@zlareb1 zlareb1 marked this pull request as ready for review November 7, 2025 12:45
@fm4v fm4v enabled auto-merge November 7, 2025 12:46
@zlareb1 zlareb1 force-pushed the fix/03212_variant_dynamic_cast_or_default branch from 85c240b to eacae27 Compare November 7, 2025 17:33
@raimannma

raimannma commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

@zlareb1 I think it might be an issue with the de-/serialization, at some points we use littleEndian and at other points we use POD-type (native format).

diff --git a/src/DataTypes/Serializations/SerializationIPv4andIPv6.cpp b/src/DataTypes/Serializations/SerializationIPv4andIPv6.cpp
index 115edacc6f7..9d3643492fe 100644
--- a/src/DataTypes/Serializations/SerializationIPv4andIPv6.cpp
+++ b/src/DataTypes/Serializations/SerializationIPv4andIPv6.cpp
@@ -128,20 +128,14 @@ template <typename IPv>
 void SerializationIP<IPv>::serializeBinary(const Field & field, WriteBuffer & ostr, const FormatSettings &) const
 {
     IPv x = field.safeGet<IPv>();
-    if constexpr (std::is_same_v<IPv, IPv6>)
-        writeBinary(x, ostr);
-    else
-        writeBinaryLittleEndian(x, ostr);
+    writeBinary(x, ostr);
 }
 
 template <typename IPv>
 void SerializationIP<IPv>::deserializeBinary(DB::Field & field, DB::ReadBuffer & istr, const DB::FormatSettings &) const
 {
     IPv x;
-    if constexpr (std::is_same_v<IPv, IPv6>)
-        readBinary(x, istr);
-    else
-        readBinaryLittleEndian(x, istr);
+    readBinary(x.toUnderType(), istr);
     field = NearestFieldType<IPv>(x);
 }

Here are 2 points where we use Little Endian for Ipv4. But then in deserializeBinary for example, we use readBinary which is not little endian necessarily.

@zlareb1

zlareb1 commented Nov 8, 2025

Copy link
Copy Markdown
Member Author

@zlareb1 I think it might be an issue with the de-/serialization, at some points we use littleEndian and at other points we use POD-type (native format).

@raimannma Interesting. Would you like to take this on and make the necessary changes? Adding a brief reproducer test would also be helpful.

@zlareb1 zlareb1 force-pushed the fix/03212_variant_dynamic_cast_or_default branch from eacae27 to 1ba225a Compare November 8, 2025 06:42
@raimannma

raimannma commented Nov 8, 2025

Copy link
Copy Markdown
Contributor

@fm4v fm4v added this pull request to the merge queue Nov 9, 2025
Merged via the queue into ClickHouse:master with commit 8f8b53c Nov 9, 2025
131 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 9, 2025
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 pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants