knowledge: streaming large result sets (server-side cursor blocked → fetchmany + write-only)#1
Open
choiyounggi wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Knowledge flush — 1 insight
Cross-Check: psycopg2 공식 usage/cursor 문서 + openpyxl optimized-modes 문서로 claim 4건 독립 교차검증(verified 3 / field-tested 1). 원 candidate의 "lxml 불필요"를 공식 문서 대조로 "메모리엔 무관·대용량 속도엔 권장"으로 정정.
Source: RNR-3440 (사내 잠재매물 주간 추출 스크립트 메모리 피크 저감). Candidate:
"QueryPie 프록시 경유로 대용량 결과를 스트리밍할 때 server-side named cursor 대신
일반 커서 +
fetchmany+ openpyxlwrite_only."Verified best-practice
Claim 1 — psycopg2 server-side (named) cursor requires a transaction; fails under autocommit.
https://github.com/psycopg/psycopg2/blob/master/doc/src/usage.rst(via Context7). Quote: "Named cursors are typically created 'WITHOUT HOLD', meaning they exist only within the current transaction. Attempting to fetch from them after a commit or in autocommit mode raises an exception."can't use a named cursor outside of transactions). → verifiedClaim 2 — a client-side (default) cursor pulls the whole result set to the client on execute;
fetchmanyonly caps the Python-list explosion.Claim 3 — openpyxl
write_onlygives near-constant memory (<10 MB); one save only; lxml is for serialization speed, not the memory saving.https://openpyxl.readthedocs.io/en/stable/optimized.html(via WebSearch). "keeping memory usage under 10Mb"; "A write-only workbook can only be saved once"; "make sure you have lxml installed" for large dumps (speed).Claim 4 — QueryPie blocks
BEGIN, so server-side cursor is impossible there.autocommit=False+ named cursor →[ENGINE] No permission to execute BEGIN statement. → field-tested. Generalized in the page to "a read-only access-control proxy that blocks transaction control", with QueryPie as the concrete example (not a product-specific page).ru_maxrss, separate processes).Existing-layer check
databases/index.md,databases/query-optimization/keyset-pagination.md,backend/python/index.md.relatedlink added to both.Routing decision
databases/query-optimization/streaming-large-result-sets.md(new page).query-optimizationfits (memory-bounding how a query's result is pulled into the app is query-execution optimization); no new category needed.databases/index.md(query-optimization section) and appended tolog.md.