Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgresql connection results inconsistent #403

Closed
gabrielmcg44 opened this issue Oct 3, 2024 · 12 comments · Fixed by #404
Closed

Postgresql connection results inconsistent #403

gabrielmcg44 opened this issue Oct 3, 2024 · 12 comments · Fixed by #404
Labels
bug Something isn't working need info Please provide additional information

Comments

@gabrielmcg44
Copy link

Describe the bug

I am migrating to use clickhouse-connect but I am facing a really weird problem when querying postgres tables

The whole test involves creating a testcontainer and a named collection. The test was working well with another clickhouse client.

Basically, depending on the filter, the queries do not return anything.

For example, if i run

        result = await self.async_client.query(
            query=statement, settings={"session_id": "random_session_id"}
        )
        print(result.column_names)

With 4 different statements, I get:

  • select * from postgresql(my_named_collection, table='my_table')
    where category = 'category_1'
    Several results

  • select * from postgresql(my_named_collection, table='my_table')
    where category = 'category_2'
    Several results

  • select * from postgresql(my_named_collection, table='my_table')
    where category != 'category_1'
    Empty list

  • select * from postgresql(my_named_collection, table='my_table')
    Empty list

@gabrielmcg44 gabrielmcg44 added the bug Something isn't working label Oct 3, 2024
@genzgd
Copy link
Collaborator

genzgd commented Oct 3, 2024

What version are you using? Is that behavior consistent? Can you turn off compression? This seems similar to #401, but I've not been able to reproduce it.

@genzgd
Copy link
Collaborator

genzgd commented Oct 3, 2024

Also it would be really helpful if you could get data from the system.query_log table that match the queries that don't return data.

@genzgd genzgd added the need info Please provide additional information label Oct 3, 2024
@gabrielmcg44
Copy link
Author

I added this "select * from system.query_log" after two contradictory queries (running in sequence)

And the two of them returned the exactly the same result (tested in a text comparator)

[('QueryStart', datetime.date(2024, 10, 3), datetime.datetime(2024, 10, 3, 23, 36, 12), datetime.datetime(2024, 10, 3, 23, 36, 12, 676841), datetime.datetime(2024, 10, 3, 23, 36, 12), datetime.datetime(2024, 10, 3, 23, 36, 12, 676841), 0, 0, 0, 0, 0, 0, 0, 0, 'default', 'CREATE DATABASE IF NOT EXISTS my_database', '', 14222981827203494986, 'Create', ['my_database'], [], [], [], [], [], 0, '', '', 1, 'my_database', 'cb2526c6-ae8a-416d-a032-b5757bb8a72d', IPv4Address('127.0.0.1'), 48430, 'my_database', 'cb2526c6-ae8a-416d-a032-b5757bb8a72d', IPv4Address('127.0.0.1'), 48430, datetime.datetime(2024, 10, 3, 23, 36, 12), datetime.datetime(2024, 10, 3, 23, 36, 12, 676841), 1, 0, '', 'afaa0fa22e1e', 'ClickHouse client', 54465, 23, 8, 8, 0, '', '', '', '', 0, 54477, '', [], {}, {}, [], [], [], [], [], [], [], [], [], [], (0, 0, UUID('00000000-0000-0000-0000-000000000000')), 'Unknown', {}), ('QueryFinish', datetime.date(2024, 10, 3), datetime.datetime(2024, 10, 3, 23, 36, 12), datetime.datetime(2024, 10, 3, 23, 36, 12, 679330), datetime.datetime(2024, 10, 3, 23, 36, 12), datetime.datetime(2024, 10, 3, 23, 36, 12, 676841), 2, 0, 0, 0, 0, 0, 0, 0, 'default', 'CREATE DATABASE IF NOT EXISTS my_database', '', 14222981827203494986, 'Create', ['my_database'], [], [], [], [], [], 0, '', '', 1, 'my_database', 'cb2526c6-ae8a-416d-a032-b5757bb8a72d', IPv4Address('127.0.0.1'), 48430, 'my_database', 'cb2526c6-ae8a-416d-a032-b5757bb8a72d', IPv4Address('127.0.0.1'), 48430, datetime.datetime(2024, 10, 3, 23, 36, 12), datetime.datetime(2024, 10, 3, 23, 36, 12, 676841), 1, 0, '', 'afaa0fa22e1e', 'ClickHouse client', 54465, 23, 8, 8, 0, '', '', '', '', 0, 54477, '', [56], {'Query': 1, 'QueriesWithSubqueries': 1, 'FileOpen': 1, 'WriteBufferFromFileDescriptorWrite': 1, 'WriteBufferFromFileDescriptorWriteBytes': 78, 'FileSync': 1, 'FileSyncElapsedMicroseconds': 1530, 'IOBufferAllocs': 1, 'IOBufferAllocBytes': 141, 'DiskWriteElapsedMicroseconds': 8, 'ContextLock': 15, 'RealTimeMicroseconds': 2591, 'UserTimeMicroseconds': 966, 'SoftPageFaults': 17, 'OSCPUVirtualTimeMicroseconds': 966, 'OSWriteBytes': 4096, 'OSReadChars': 434, 'OSWriteChars': 1138, 'LogTrace': 3, 'LogDebug': 1, 'LogInfo': 3}, {}, [], [], ['Atomic'], [], [], [], [], [], [], [], (0, 0, UUID('00000000-0000-0000-0000-000000000000')), 'None', {})]

@gabrielmcg44
Copy link
Author

Let me know if I can provide some more info

@gabrielmcg44
Copy link
Author

Yes, the behavior is consistent. Tried the same test several times

@gabrielmcg44
Copy link
Author

Tried it passing compress=False to where I create the client, and it worked!

But why? Should I keep it uncompressed? Wont I lose performance?

@genzgd
Copy link
Collaborator

genzgd commented Oct 4, 2024

What version of clickhouse-connect are you using? There were changes to lz4 compression that might have a bug. In the meantime you can try 'zstd' compression instead

@genzgd
Copy link
Collaborator

genzgd commented Oct 4, 2024

I have tried another fix to the lz4 compression in version 0.8.3. Unfortunately I still haven't been able to reproduce this locally.

@gabrielmcg44
Copy link
Author

just tried but zstd also fail

@genzgd
Copy link
Collaborator

genzgd commented Oct 5, 2024 via email

@gabrielmcg44
Copy link
Author

tested, 0.8.2 with zstd works, thanks

@genzgd
Copy link
Collaborator

genzgd commented Oct 7, 2024

If you have a chance, please test with lz4 as well (that's the default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need info Please provide additional information
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants