Skip to content

ISSUES-2973 support nested json struct for visitParamExtractRaw - #2974

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
zhang2014:fix/nested_json_for_visitRaw
Sep 1, 2018
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
zhang2014:fix/nested_json_for_visitRaw

Conversation

@zhang2014

Copy link
Copy Markdown
Contributor

@zhang2014

zhang2014 commented Aug 28, 2018 •

Copy link
Copy Markdown
Contributor Author

Take the best result of the three runs.

Compile Parameters:

cmake .. -DCMAKE_CXX_COMPILER=`which g++-8 ` -DCMAKE_C_COMPILER="`which gcc-8`" -DENABLE_TESTS=0  -DUSE_UNWIND=0 -DENABLE_CLICKHOUSE_COMPRESSOR=0 -DENABLE_MONGODB=1 -DENABLE_JEMALLOC=0 -DCMAKE_BUILD_TYPE=Release

Before

[
{
    "hostname": "i-2okyk0c6",
    "main_metric": "max_rows_per_second",
    "num_cores": 16,
    "num_threads": 16,
    "parameters": {
        "param": ["'{"myparam":"test_string"}'", "'{"myparam":{"nested_1":"test_string","nested_2":"test_2"}}'", "'{"myparam":{"nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2"}}'"]
    },
    "ram": 33736384512,
    "runs": [
        {
            "max_rows_per_second": 21752173.000000,
            "parameters": {
                "param": "'{"myparam":"test_string"}'"
            },
            "query": "SELECT count() FROM system.numbers WHERE NOT ignore(visitParamExtractRaw(materialize('{"myparam":"test_string"}'), 'myparam'))"
        },
        {
            "max_rows_per_second": 7467469.000000,
            "parameters": {
                "param": "'{"myparam":{"nested_1":"test_string","nested_2":"test_2"}}'"
            },
            "query": "SELECT count() FROM system.numbers WHERE NOT ignore(visitParamExtractRaw(materialize('{"myparam":{"nested_1":"test_string","nested_2":"test_2"}}'), 'myparam'))"
        },
        {
            "max_rows_per_second": 1936649.000000,
            "parameters": {
                "param": "'{"myparam":{"nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2"}}'"
            },
            "query": "SELECT count() FROM system.numbers WHERE NOT ignore(visitParamExtractRaw(materialize('{"myparam":{"nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2"}}'), 'myparam'))"
        }
    ],
    "server_version": "18.10.3",
    "test_name": "visit_param_extract_raw",
    "time": "2018-08-31 15:18:16"
}
]

After

[
{
    "hostname": "i-2okyk0c6",
    "main_metric": "max_rows_per_second",
    "num_cores": 16,
    "num_threads": 16,
    "parameters": {
        "param": ["'{"myparam":"test_string"}'", "'{"myparam":{"nested_1":"test_string","nested_2":"test_2"}}'", "'{"myparam":{"nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2"}}'"]
    },
    "ram": 33736384512,
    "runs": [
        {
            "max_rows_per_second": 17394195.000000,
            "parameters": {
                "param": "'{"myparam":"test_string"}'"
            },
            "query": "SELECT count() FROM system.numbers WHERE NOT ignore(visitParamExtractRaw(materialize('{"myparam":"test_string"}'), 'myparam'))"
        },
        {
            "max_rows_per_second": 7092361.000000,
            "parameters": {
                "param": "'{"myparam":{"nested_1":"test_string","nested_2":"test_2"}}'"
            },
            "query": "SELECT count() FROM system.numbers WHERE NOT ignore(visitParamExtractRaw(materialize('{"myparam":{"nested_1":"test_string","nested_2":"test_2"}}'), 'myparam'))"
        },
        {
            "max_rows_per_second": 2552266.000000,
            "parameters": {
                "param": "'{"myparam":{"nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2"}}'"
            },
            "query": "SELECT count() FROM system.numbers WHERE NOT ignore(visitParamExtractRaw(materialize('{"myparam":{"nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2","nested_1":"test_string","nested_2":"test_2"}}'), 'myparam'))"
        }
    ],
    "server_version": "18.10.3",
    "test_name": "visit_param_extract_raw",
    "time": "2018-08-31 15:05:25"
}
]

@alexey-milovidov

alexey-milovidov commented Aug 30, 2018 •

Copy link
Copy Markdown
Member

Thank you!

PS. The performance test you quote is incorrect because
visitParamExtractRaw('{"myparam":"test_string"}', 'myparam')
is a constant expression and it is calculated just once.

(it's obvious because otherwise you cannot get 2+ billion rows/sec. on single core.)

To be sure, you can transform a string to non-constant with materialize function:

visitParamExtractRaw(materialize('{"myparam":"test_string"}', 'myparam'))

@alexey-milovidov alexey-milovidov left a comment

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.

.

res_data.push_back(*pos);
static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars_t & res_data)
{
std::vector<char> expect_end;

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 will lead to allocation/deallocation inside a loop.
We can use PODArray with AllocatorWithStackMemory with for example, 64 bytes of automatic memory.

struct ExtractRaw
{
static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars_t & res_data)
inline static void skipAfterQuotationIfNeed(const UInt8 *& pos, const UInt8 * end, ColumnString::Chars_t & res_data)

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 would be more clear if we just put this code where it is called.
PS. I think, it should be named skipAfterBackslashIfNeed.

@@ -0,0 +1,31 @@
<test>

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.

materialize should be added.

@alexey-milovidov alexey-milovidov self-assigned this Aug 30, 2018
@zhang2014
zhang2014 force-pushed the fix/nested_json_for_visitRaw branch from 746e6e9 to a1f2b9a Compare August 31, 2018 07:25
@zhang2014

Copy link
Copy Markdown
Contributor Author

Done and update #2974 (comment)

@alexey-milovidov

Copy link
Copy Markdown
Member

Ok.
Performance drop is significant, but it's ok as the cost for correctness of this rather specific function.

@alexey-milovidov
alexey-milovidov merged commit 087570e into ClickHouse:master Sep 1, 2018
alexey-milovidov pushed a commit to evillique/ClickHouse that referenced this pull request Nov 29, 2026
0.18.0 and 0.19.0 made `-ftime-trace` uncacheable (mozilla/sccache#2834),
which 27 CI build types pass through -DENABLE_BUILD_PROFILING=1, so CI
stayed on 0.17.0. 0.20.0 hashes the flag again and writes no trace on a
cache hit (mozilla/sccache#2956). It also leaves CARGO_TARGET_DIR and
CARGO_BUILD_* out of Rust keys (ClickHouse#3050) and hashes the C/C++ input file
name (ClickHouse#2974).

Measured locally with CI's cmake flags and a local disk cache, second
build from a fresh build directory at the same path:
- amd_binary clickhouse-bundle: 1562 s cold, 147 s warm; C/C++ 17715 of
  17717 hits (the 2 misses are openldap's generated version files with
  __DATE__/__TIME__), Rust 603 of 603; no hit wrote a time trace.
- amd_asan_ubsan dbms: 1934 s cold, 95 s warm; C/C++ 16237 of 16239,
  Rust 529 of 529.
- PR-build environment (READ_ONLY, anonymous S3): the server starts, a
  miss compiles, the write is refused, warn_on_low_sccache_hit_rate
  parses the stats. 0.20.0 additionally counts an anonymous 403 on a
  missing key as a read error (ClickHouse#2967); it is still a miss.

0.20.0 treats `--embed-dir` as uncacheable, so the 4 _jieba sources
(6.9 s of compile) are always compiled. 0.20.0 does not read 0.17.0
entries: every build type is cold once after this lands.

Related: ClickHouse#127827

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit to lazerg/ClickHouse that referenced this pull request Nov 30, 2026
0.18.0 and 0.19.0 made `-ftime-trace` uncacheable (mozilla/sccache#2834),
which 27 CI build types pass through -DENABLE_BUILD_PROFILING=1, so CI
stayed on 0.17.0. 0.20.0 hashes the flag again and writes no trace on a
cache hit (mozilla/sccache#2956). It also leaves CARGO_TARGET_DIR and
CARGO_BUILD_* out of Rust keys (ClickHouse#3050) and hashes the C/C++ input file
name (ClickHouse#2974).

Measured locally with CI's cmake flags and a local disk cache, second
build from a fresh build directory at the same path:
- amd_binary clickhouse-bundle: 1562 s cold, 147 s warm; C/C++ 17715 of
  17717 hits (the 2 misses are openldap's generated version files with
  __DATE__/__TIME__), Rust 603 of 603; no hit wrote a time trace.
- amd_asan_ubsan dbms: 1934 s cold, 95 s warm; C/C++ 16237 of 16239,
  Rust 529 of 529.
- PR-build environment (READ_ONLY, anonymous S3): the server starts, a
  miss compiles, the write is refused, warn_on_low_sccache_hit_rate
  parses the stats. 0.20.0 additionally counts an anonymous 403 on a
  missing key as a read error (ClickHouse#2967); it is still a miss.

0.20.0 treats `--embed-dir` as uncacheable, so the 4 _jieba sources
(6.9 s of compile) are always compiled. 0.20.0 does not read 0.17.0
entries: every build type is cold once after this lands.

Related: ClickHouse#127827

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants