Restricting by a dj.Top expression fails on MySQL (error 1235)
メンテナーはふだん 6 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 62/100
調査の方向性
Start at make_condition in condition.py around line 455, where a query-expression restriction is rendered as an IN subquery, and check how a _top adds ORDER BY and LIMIT to that SQL. Run the reproducer from the issue against MySQL 8.0 and PostgreSQL 16 to confirm the error 1235 on MySQL and the count of 6 on PostgreSQL. Done when the query returns 6 on both backends, with the MySQL-compatible form the issue describes (a derived table) as one option.
索引モデルが issue の本文から書いたものです。
説明
Using a dj.Top expression as a restriction (S & (T & dj.Top(...))) fails on MySQL, which does not support LIMIT inside an IN subquery. PostgreSQL returns the correct result.
Reproduced on master @ 3c912c46 against MySQL 8.0 and PostgreSQL 16. Connection via DJ_HOST/DJ_USER/DJ_PASS/DJ_BACKEND. Found while benchmarking subquery pruning (#1665).
Reproducible example
import datajoint as dj
schema = dj.Schema("repro_top")
@schema
class T(dj.Manual):
definition = """
t_id : int32
---
x : int32
y : int32
"""
@schema
class S(dj.Manual):
definition = """
-> T
s_id : int32
"""
T.insert([(i, i, 100 - i) for i in range(10)], skip_duplicates=True)
S.insert([(i, j) for i in range(10) for j in range(2)], skip_duplicates=True)
q = S & (T & dj.Top(3, "x")) # S rows whose T is among the 3 with the smallest x
print(len(q.to_dicts())) # expected: 6
Actual
MySQL:
pymysql.err.NotSupportedError: (1235, "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'")
PostgreSQL: 6 (correct).
Expected
6 on both backends.
Cause
make_condition (condition.py:455) renders a query-expression restriction as (attrs) IN (<condition.make_sql(attrs)>). When the condition has a _top, its SQL ends in ORDER BY ... LIMIT n, which MySQL rejects inside IN.
The usual workaround is to wrap it in a derived table, IN (SELECT ... FROM (<subquery with LIMIT>) AS x). MySQL accepts that form, and it is equivalent on PostgreSQL.
- 主要言語
- Python
- スター
- 198
- フォーク
- 103
- 平均マージ
- 6日 1時間
- マージ済み PR(30日)
- 10
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
datajoint/datajoint-python のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
datajoint/datajoint-python#1703 ·
メンテナーはふだん 6 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
datajoint/datajoint-python#1702 ·
メンテナーはふだん 6 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
datajoint/datajoint-python#1701 ·
メンテナーはふだん 6 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
datajoint/datajoint-python#1691 ·
メンテナーはふだん 6 日以内に返信
-
dependencies needs-discussion
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
datajoint/datajoint-python#1687 ·
メンテナーはふだん 6 日以内に返信
datajoint/datajoint-python の issue をすべて見る
似ている issue
-
needs-triage
難易度 1/5 1〜3時間 初心者へのやさしさ 85/100
gke-labs/kube-agents#6620 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
open-webui/open-webui#34719 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
cognition
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
One non-object JSON record makes the session catalog exit対応中かも @he-yufeng が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
collabnix/awesome-mcp-lists#433 ·
メンテナーはふだん 4 日以内に返信