Skip to content

Add SQL/1211. Queries Quality and Percentage (Claude Sonnet 4.6 Exten…#318

Merged
myoshi2891 merged 6 commits into
mainfrom
dev-from-macmini
Mar 4, 2026
Merged

Add SQL/1211. Queries Quality and Percentage (Claude Sonnet 4.6 Exten…#318
myoshi2891 merged 6 commits into
mainfrom
dev-from-macmini

Conversation

@myoshi2891

@myoshi2891 myoshi2891 commented Mar 4, 2026

Copy link
Copy Markdown
Owner

…ded)

  • Queries_Quality_and_Percentage_pandas.md
  • Queries_Quality_and_Percentage_postgresql.md
  • README.html

以下の2点を Queries_Quality_and_Percentage_postgresql.md に反映しました:

  1. WHERE query_name IS NOT NULL の復元:
    • 推奨解のクエリ(行 201 付近)にて WHERE query_name IS NOT NULL を追加し、意図せぬ NULL グループが発生して WA になるリスクを回避しました。
    • ボトルネックの特定箇所および変更点の差分から WHERE IS NOT NULL を削除したという記述を取り下げました。
    • Mermaid の図解 2 にも WHERE query_name IS NOT NULL を追加してフローを整合させました。
  2. FLOAT キャストとコメントの修正:
    • NUMERIC ではなくネイティブの FLOAT 演算となるよう AVG(rating::float8 / position)::NUMERIC 으로変更しました。
    • 以降の説明や Diff、およびMermaid図の該当箇所での表記も float8(倍精度浮動小数点) 等として、元の "FLOAT 計算で高速化" の主張が正しく活きる形に統一しました。

Mermaid図の不要な矢印 D --> E を D --> F に修正し、コミットしました。

これにより、poor_query_percentage の計算結果(Node D)は不要な ::NUMERIC キャスト(Node E)を通らずに、直接 ROUND(Node F)に向かう正しいフローチャートになりました。

  • ✅ 改善版(推奨・要件緩和時) へのセクション名変更
  • 実行時間のブレと精度のトレードオフに関する警告ブロックの追加
    • 223ms → 221ms のパフォーマンス向上はベンチマークのノイズの可能性がある旨を明記。
    • float8 利用による浮動小数点演算特有の丸め誤差(Precision Loss)のリスクを追記。
    • 基本的には ROUND(..., 2) でカバーされるが、金融系など厳密な精度が求められるケースでは、パフォーマンスを犠牲にしても元の NUMERIC 計算を維持する方針を推奨。
markdown
>**⚠️ 注意: 実行時間のブレと精度のトレードオフ**
> LeetCode 上での`223 ms → 221 ms` の変化は**ベンチマークのブレの範囲内**(ノイズ)である可能性が高いです。
> 中間集計に`float8`(倍精度浮動小数点)を利用すると、ネイティブ CPU 処理により微小なパフォーマンス向上が期待できますが、同時に**浮動小数点演算特有の丸め誤差(Precision Loss)**が発生するリスクがあります。
> 本問のように`ROUND(..., 2)` で小数第2位までに丸める場合は許容範囲内となりますが、金融系やより厳密な精度が求められるケースでは、パフォーマンスを犠牲にしても**元解法の`NUMERIC` のまま計算するアプローチ**が推奨されます。

また、あわせてHTML側(Mermaid図の\n<br>などになった点等)の変更も含まれてコミットされています。

Pandas (Queries_Quality_and_Percentage_pandas.md) の修正:

  1. 重複していた queries_stats の実装コードを整理し、片方を「参考実装(初期方針・非推奨)」セクションに移動し、もう片方を「最終提出版(最適化実装)」として明示しました。付随する見出し番号等も単一の解説フローになるよう修正しています。
  2. float64 の例示について、float64(0.07) ≈ 0.07000000000000000666... と IEEE-754 の近似表現に改め、「近似ではあるが、本問の ROUND_HALF_UP(小数2桁丸め)には十分な精度を持ち実用上安全」という旨の補足を追記しました。

PostgreSQL (Queries_Quality_and_Percentage_postgresql.md) の修正:

  1. 50行目および要点解説における WHERE query_name IS NOT NULL のコメントを、「重複行対策」から「NULL値による独立したNULLグループの生成を防ぐため」という正確な意図へ修正しました。
  2. インデックス利用時の計算量について、断定的な Index Scan → O(N log N) を改め、「実行計画依存: work_mem や n_distinct に基づき HashAggregate (O(N)) または GroupAggregate+Sort (O(N log N)) が選択される」という条件付きの説明に変更しました。

修正を反映し、再度コミット。

Pandas (Queries_Quality_and_Percentage_pandas.md) の修正:

ROUND_HALF_UP の説明: np.floor(x*100+0.5)/100 が SQL の ROUND() と一致するのは本問のような非負データの範囲に限定される点を明記しました。注釈を追加し、負の数(例: ROUND(-1.5))の場合に PostgreSQL と比較して挙動や結果が異なる点にも触れつつ、今回は quality 等が非負のため安全であることを補足しました。
copy=False の説明: コピーを全く行わない(ゼロコピー)と断言していた箇所を、「コピー回避を試みる」というベストエフォートな表現にすべて修正しました。
PostgreSQL (Queries_Quality_and_Percentage_postgresql.md) の修正:

FILTER の説明: SUM(CASE WHEN...) よりも「より高速・簡潔」としていた箇所を、「簡潔で可読性が高い」という表現に修正し、純粋なパフォーマンス上の優位性を断言する内容を取り下げました。
Mermaid図内の集計手法ラベル: Bノードに書かれていた固定の "Hash Aggregate" を、事前に修正したテキストと一致するよう「HashAggregate / GroupAggregate (プランナがコスト等から選択)」に変更しました。

…ded)

- Queries_Quality_and_Percentage_pandas.md
- Queries_Quality_and_Percentage_postgresql.md
- README.html
@netlify

netlify Bot commented Mar 4, 2026

Copy link
Copy Markdown

Deploy Preview for algorithm-datastructures-math-studies ready!

Name Link
🔨 Latest commit b9d2003
🔍 Latest deploy log https://app.netlify.com/projects/algorithm-datastructures-math-studies/deploys/69a80a218f179d000815abde
😎 Deploy Preview https://deploy-preview-318--algorithm-datastructures-math-studies.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

ウォークスルー

LeetCode 1211(Queries Quality and Poor Query Percentage)用に、Pandas実装(公開関数 queries_stats)、PostgreSQL参照実装、対話式開発用・公開HTMLドキュメントを追加し、サイトインデックスを更新しました。NULL処理、SQL互換の丸め、最適化案と検証例を含みます。

変更

コホート / ファイル サマリー
Pandas 実装
SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_pandas.md
公開シグネチャ def queries_stats(queries: pd.DataFrame) -> pd.DataFrame を追加。query_name NULL 除外、score = rating/positionpoor = (rating < 3) を float64 でベクトル化し groupby->mean により qualitypoor_query_percentage を算出。SQL準拠の ROUND_HALF_UP 相当の丸め、コピー回避の高速実装、検証トレースと複数実装例を記載。
PostgreSQL 参照実装
SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_postgresql.md
PostgreSQL 16.6+ 向けの主クエリ(GROUP BY + FILTER)を提示。NULL 排除、NUMERIC/float8 キャスト案、CTE/LATERAL 代替、ROUNDおよびパフォーマンス最適化(キャスト戦略・インデックス助言)を追加。
開発用対話HTML(内部)
SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/README.html
React ベースの対話式ステップ解説を含む自己完結型ドキュメントを追加。アルゴリズムフロー図、Python/Pandas スニペット(最適化版含む)、丸め・COWの落とし穴、複雑度解析、コードハイライトを収載。
公開用HTML
public/SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/README.html
公開向けHTMLを追加。対話UI、図表、最適化例、コピー機能、処理フローSVGなどを含む。
サイトメタデータ
public/index.html
サイト集計を更新(レッスン数 160→161)、新しいSQL項目表示を追加、生成タイムスタンプを 2026-03-04 に更新。

推定コード検証工数

🎯 4 (Complex) | ⏱️ ~45 分

🐰 新しいクエリの朝に跳ねて、
NULLをよけてスコアを描き、
グループで丸めて答えを結び、
PandasとSQLが並んで踊る、
161の光へぴょんと。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、追加されるファイル群(Queries_Quality_and_Percentage_pandas.md、PostgreSQL版、README.html)とその問題領域(SQL/LeetCode 1211)を明確に示しており、変更セットの主要な目的と一致している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed プルリクエストの説明はチェンジセット内の3つのファイル(Pandas実装、PostgreSQL実装、HTMLドキュメント)の追加および修正内容と関連しており、各ファイルでの具体的な変更点(WHERE句の復元、FLOATキャスト修正、Mermaid図の修正、精度警告の追加など)が詳細に説明されています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@SQL/Leetcode/Basic` select/1211. Queries Quality and Percentage/Claude Sonnet
4.6 Extended/Queries_Quality_and_Percentage_postgresql.md:
- Around line 201-223: The query removed the WHERE query_name IS NOT NULL filter
causing a NULL group to appear and risk WA; restore a WHERE clause filtering out
NULL query_name before aggregation (i.e., add back "WHERE query_name IS NOT
NULL" prior to the GROUP BY) so the SELECT of query_name, ROUND(AVG(... ) AS
quality, and ROUND(... ) AS poor_query_percentage only aggregates non-NULL
groups and matches earlier assumptions about inputs.
- Around line 203-220: The comment claiming "FLOAT 演算で高速化" is incorrect because
numeric literal 1.0 is treated as NUMERIC in PostgreSQL making the expression
ROUND(AVG(rating * 1.0 / position)::NUMERIC, 2) still all-NUMERIC; fix by either
(A) making the calculation actually use floating point (e.g., replace the
intermediate expression with an explicit double precision cast like
rating::double precision / position::double precision and then cast back to
NUMERIC only if needed in ROUND/::NUMERIC) or (B) keep the current numeric
expression but remove/adjust the comment to not claim FLOAT-based speedup;
update references around the AVG/ROUND expression and the accompanying comment
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 009fbd3e-6275-40f5-8ab7-3528bea83ae7

📥 Commits

Reviewing files that changed from the base of the PR and between aa48b91 and 90b00e9.

📒 Files selected for processing (5)
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_pandas.md
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_postgresql.md
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/README.html
  • public/SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/README.html
  • public/index.html

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@SQL/Leetcode/Basic` select/1211. Queries Quality and Percentage/Claude Sonnet
4.6 Extended/Queries_Quality_and_Percentage_postgresql.md:
- Around line 231-243: The Mermaid flow incorrectly shows the ::NUMERIC cast
(node E) applied to both branches because of the edge D --> E; update the
diagram so only the quality branch (node C / the path that computes
poor_query_percentage) flows into E, and remove or redirect the edge from D so
the FILTER/count branch goes directly to F or G as in the real SQL; specifically
ensure C --> E remains and D does not point to E (e.g., remove D --> E and add D
--> F or D --> G) so that ::NUMERIC is only on the quality side.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1c38da3a-705c-4525-a2bf-e8bfa7fece72

📥 Commits

Reviewing files that changed from the base of the PR and between 90b00e9 and a61e983.

📒 Files selected for processing (1)
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_postgresql.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@SQL/Leetcode/Basic` select/1211. Queries Quality and Percentage/Claude Sonnet
4.6 Extended/Queries_Quality_and_Percentage_postgresql.md:
- Around line 196-221: Update the explanatory comments around the modified
expression ROUND(AVG(rating::float8 / position)::NUMERIC, 2) and the section
title to state that the observed 2ms improvement (223ms → 221ms) may be within
benchmark noise and not statistically significant, and also add a precision
warning that using float8 for the intermediate AVG(rating::float8 / position)
can introduce floating‑point rounding errors compared to NUMERIC; recommend
keeping the original NUMERIC variant for cases needing strict
arbitrary‑precision (e.g., financial calculations) while noting that rounding to
2 decimal places usually makes float8 acceptable here.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1855c509-3401-47f5-8a97-a448dba2f187

📥 Commits

Reviewing files that changed from the base of the PR and between a61e983 and 206cc54.

📒 Files selected for processing (1)
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_postgresql.md

@myoshi2891

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@SQL/Leetcode/Basic` select/1211. Queries Quality and Percentage/Claude Sonnet
4.6 Extended/Queries_Quality_and_Percentage_pandas.md:
- Around line 209-217: The document shows two implementations of the function
queries_stats and duplicated section numbering, which makes it unclear which is
the final submission; remove one implementation and clearly label the other as
the canonical "final" submission; move the removed implementation into a new
"参考実装 / Reference implementation" subsection (or vice‑versa) and ensure only the
final queries_stats signature, return columns and order remain in the main
solution section, and update section headings so numbering does not restart and
readers see a single definitive implementation.
- Around line 259-261: Update the description for the float64 example: replace
the assertive "float64(0.07) = 0.07000000000000000..." with the more accurate
IEEE‑754 representation "float64(0.07) ≈ 0.07000000000000000666..." and add a
brief qualifier that, while float64 is still an approximation, its precision is
sufficient for the ROUND_HALF_UP two‑decimal rounding used in this exercise (so
practically safe). Locate and edit the lines showing "float32(0.07) = ..." and
"float64(0.07) = ..." and adjust the float64 explanatory sentence accordingly.

In `@SQL/Leetcode/Basic` select/1211. Queries Quality and Percentage/Claude Sonnet
4.6 Extended/Queries_Quality_and_Percentage_postgresql.md:
- Line 50: コメントが実装意図とずれているので、"WHERE query_name IS NOT NULL          --
NULLクエリ名は除外(重複行対策)" を修正してください: WHERE句がGROUP
BYより先に適用されるため、ここは「重複行対策」ではなく「NULL値による独立したNULLグループの生成を防ぐためにNULLを除外する」ことを説明する旨に変更し、該当するコメント(WHERE
query_name IS NOT NULL の横)をその説明に置き換えてください。
- Line 127: The sentence asserting "Index Scan → O(N log N)" for `query_name` is
incorrect because PostgreSQL may choose HashAggregate (expected O(n)) or
GroupAggregate+Sort (O(n log n)) depending on the plan; update the text around
`query_name` to state that complexity is execution-plan dependent and clarify
that although an index can enable index-based grouping/sorting, the planner's
choice (HashAggregate vs GroupAggregate+Sort) is influenced by `work_mem`,
`n_distinct`/statistics, estimated number of groups, and the cost model; replace
the definitive O(N log N) claim with a conditional note like "may be O(n)
(HashAggregate) or O(n log n) (SortAggregate/GroupAggregate) depending on
execution plan and configuration" and reference `HashAggregate`,
`GroupAggregate`, and `Index Scan` by name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0848714e-34a5-4f6d-b768-eae1d0199c7a

📥 Commits

Reviewing files that changed from the base of the PR and between 206cc54 and 145df53.

📒 Files selected for processing (2)
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_pandas.md
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_postgresql.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@SQL/Leetcode/Basic` select/1211. Queries Quality and Percentage/Claude Sonnet
4.6 Extended/Queries_Quality_and_Percentage_pandas.md:
- Line 356: Update the statement about ROUND_HALF_UP to limit its claimed
equivalence to SQL ROUND() to non-negative values: change the line that
currently reads "| ROUND_HALF_UP       | `np.floor(x*100+0.5)/100` で SQL
`ROUND()` と完全一致 |" to explicitly say that `np.floor(x*100+0.5)/100` matches SQL
`ROUND()` only for non-negative inputs (e.g., “本問の非負データ範囲では
`np.floor(x*100+0.5)/100` は SQL `ROUND()` と一致”), and add a brief note
referencing the differing behavior on negatives (e.g., PostgreSQL’s `round(-1.5)
= -2` vs the NumPy expression giving `-1`) while emphasizing that quality score
and percentage are non-negative here.
- Around line 248-249: Update the table descriptions that claim `copy=False`
does zero-copy and reference-passes (the cell showing `pd.DataFrame({...},
copy=False)`) to a best-effort wording such as “コピー抑制を試みる” or “コピー回避を試みる” and
similarly change any absolute phrasing elsewhere (including the row referencing
`.to_numpy()` behavior) so they state that pandas will attempt to avoid copies
but may still copy for index alignment or dtype conversion; make this change for
all occurrences of the `copy=False` description in the markdown.

In `@SQL/Leetcode/Basic` select/1211. Queries Quality and Percentage/Claude Sonnet
4.6 Extended/Queries_Quality_and_Percentage_postgresql.md:
- Line 114: Update the description for the table cell containing "`FILTER (WHERE
rating < 3)`" to replace the claim "より高速・簡潔" with wording that reflects
correctness and nuance—e.g., "簡潔で可読性が高い"—so it no longer asserts a blanket
performance advantage over `SUM(CASE WHEN...)`; keep the note that FILTER is
PostgreSQL-specific and preferred for clarity.
- Around line 235-236: The Mermaid diagram currently hardcodes "Hash Aggregate"
in node B ("GROUP BY query_name<br>Hash Aggregate"), which contradicts your
earlier explanation that aggregation strategy is plan-dependent; update that
node label to mention both possibilities (e.g., "HashAggregate / GroupAggregate
(SortAggregate) — chosen by planner based on cost, work_mem, stats,
enable_hashagg and spill prediction") or otherwise annotate the diagram to show
both options so it aligns with the text; edit the Mermaid node B (and any
similar hardcoded aggregation labels) to reflect the dual possibilities rather
than a fixed "Hash Aggregate".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b8147fae-0e0b-4ddb-9046-ef20034caa5e

📥 Commits

Reviewing files that changed from the base of the PR and between 145df53 and 157ffd7.

📒 Files selected for processing (2)
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_pandas.md
  • SQL/Leetcode/Basic select/1211. Queries Quality and Percentage/Claude Sonnet 4.6 Extended/Queries_Quality_and_Percentage_postgresql.md

@myoshi2891 myoshi2891 merged commit ddc87f6 into main Mar 4, 2026
6 checks passed
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.

1 participant