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

'inherit_cache' attribute warning when executing a query #276

Open
AviSarmani opened this issue Nov 22, 2023 · 1 comment
Open

'inherit_cache' attribute warning when executing a query #276

AviSarmani opened this issue Nov 22, 2023 · 1 comment

Comments

@AviSarmani
Copy link

To Reproduce
In database:

CREATE TABLE test_01
( `first_col` String)
ENGINE = Log;
CREATE TABLE test_02
( `first_col` String)
ENGINE = Log;

Code:

from clickhouse_sqlalchemy import Table
from clickhouse_sqlalchemy import select as chselect

test_01 = Table(
    "test_01",
    metadata,
    autoload_with=engine,
)

test_02 = Table(
    "test_02",
    metadata,
    autoload_with=engine,
)

sel = (
    chselect(test_01.c.first_col)
    .select_from(test_01.join(test_02, test_01.c.first_col == test_02.c.first_col))
    .limit(1)

connection = engine.connect()
result = connection.execute(sel)

This gives the following warning:
SAWarning: Class Select will not make use of SQL compilation caching as it does not set the 'inherit_cache' attribute to True. This can have significant performance implications including some performance degradations in comparison to prior SQLAlchemy versions. Set this attribute to True if this object can make use of the cache key generated by the superclass. Alternatively, this attribute may be set to False which will disable this warning. (Background on this warning at: https://sqlalche.me/e/20/cprf)

If I set the attribute on our Select object:


to select.inherit_cache = False, the warning disappears but we don't use the cache

If I set it to True we get a an error and would be nice if we could use the caching mechanism:

File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1416, in execute
    return meth(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 516, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1631, in _execute_clauseelement
    compiled_sql, extracted_params, cache_hit = elem._compile_w_cache(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 700, in _compile_w_cache
    compiled_sql = compiled_cache.get(key)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/_collections.py", line 535, in get
    item = self._data.get(key)
TypeError: unhashable type: 'dict

If we can't use the cache, we should set it to false to get rid of the warning.

Versions
Clickhouse: 23.7.1.2470
Sqlalchemy: 2.0.23
clickhouse-sqlalchemy: 0.3.0

@aronbierbaum
Copy link
Contributor

aronbierbaum commented Apr 2, 2024

The caching failure is caused by the changes in 16fa7b3 which result in a unhashable dict stored in Join.full. @xzkostyan do you have any ideas on how to allow caching while still supporting JOINs?

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

No branches or pull requests

2 participants