Repository navigation
feat(explain): numeric cost and gap columns in the EXPLAIN CSV export - #1237
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Notes from review:
Files Reviewed (9 files)
Previous Review Summaries (2 snapshots, latest commit 2f0298b)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 2f0298b)Status: No Issues Found | Recommendation: Merge Notes from review:
Files Reviewed (9 files)
Previous review (commit fd7ce92)Status: No Issues Found | Recommendation: Merge Notes from review:
Files Reviewed (9 files)
Reviewed by claude-sonnet-5.5 · Input: 248 · Output: 2K · Cached: 296.5K Review guidance: REVIEW.md from base branch |
fd7ce92 to
2f0298b
Compare
debba
left a comment
There was a problem hiding this comment.
Thanks for this! Having a single raw-value row builder (getExplainTableRow) feed both the tree view and the CSV, with each side doing only its display formatting, is a really nice cleanup. Replacing getMismatchMagnitude and the inline copies with getRowEstimateGap keeps the amber highlight exactly equivalent (gap >= 4). Every point in #1231 is covered.
The code itself is fine. What blocks it is the rebase after #676:
packages/web-ui/src/utils/explainTableExport.ts:saveExplainTableCsvnow takesplatformand usesdownloadTextFileinstead ofsave+writeTextFile.VisualExplainView.tsx: aplatformargument and dependency were added.
Both are easy: keep platform and add your toast code on top. One trap to watch for: git auto-merges packages/web-ui/tests/components/explain/VisualExplainView.test.tsx, but the result is broken. Main only mocks writeFile, while your new CSV tests still use mockWriteTextFile, which is no longer declared, so the whole suite fails. Those tests need rewriting against writeFile / downloadTextFile, like the raw-export tests on main.
Small nits:
csvNumberusesString(value), so very large or very small values end up as1e+21. Unlikely for costs.- The export now goes through
downloadTextFile, so it would be good to also check success, cancel and error intabularis web, not only in the desktop app.
Follow-ups from the review of TabularisDB#1184. - The CSV now has separate startup_cost and total_cost columns and writes estimate_gap as a plain number, so all three sort and chart in a spreadsheet. Unavailable values stay empty, never 0. - The table view and the CSV both build their rows with getExplainTableRow, so the values they show cannot drift apart. getRowEstimateGap replaces the private mismatch helper and the two inline copies of the same maths. - Every record ends with CRLF, as RFC 4180 describes. - A successful export shows a success toast instead of a modal alert. A failed one shows an error toast that keeps the underlying reason and stays until dismissed. - Re-indent the table block in ExplainTableView and use a more natural ja translation for the table title. Closes TabularisDB#1231
String(value) turns very large or very small numbers into 1e+21 or 1.5e-7. The CSV now expands them to plain decimals, keeping the digits String() picks, so normal values are unchanged and no precision is lost.
2f0298b to
0ebf89d
Compare
|
Thanks for the review, and for flagging the test file trap. It would have been easy to miss. Rebased onto main:
Nits:
Typecheck ( |
debba
left a comment
There was a problem hiding this comment.
Thanks for the careful rebase, and for rewriting the CSV tests against writeFile instead of letting the broken auto-merge through. Going through the real Tauri platform path (dialog, downloadTextFile, writeFile) is exactly what I had in mind, and the plain string rejection case is a nice touch. The plainDecimal fix is also cleaner than I expected: keeping the digits String() picks and only moving the decimal point means normal values don't change at all.
I checked it out locally. The explain package tests (183), the three web-ui test files (36) and pnpm build all pass, and CI is green. Every point from my previous review is covered, so I'm approving.
Two things that aren't for this PR, just possible follow-ups if you feel like it:
- The raw plan export in
VisualExplainView.tsxstill uses the modalshowAlert, so the two export buttons in the same view now give different feedback. Moving it to toasts too would make them consistent. - In web mode
BrowserPlatformCapabilities.downloadFilealways returnstrue, so the success toast shows even if the user cancels the browser's save prompt. Your "download started" idea makes sense, but I'd handle it once for every download rather than here.
I'll run a few manual checks in the desktop app before merging, since that's the one path you couldn't try by hand. Thanks again!
Summary
Follow-ups from the review of #1184, as listed in #1231. The EXPLAIN table CSV now has numeric cost and estimate gap columns, the table view and the CSV build their rows with the same code, a successful export shows a toast, and a failed one shows the reason.
What changed
Numeric columns
cost("0 - 150.25") is split intostartup_costandtotal_cost, both plain numbers.estimate_gapis a plain number (3, not"3.00x").0, as before. A real startup cost of0is still written as0. Non-finite values are written as empty cells.3.3333333333333335.1e21is written as1000000000000000000000and1.5e-7as0.00000015, with the same digitsString()gives, so no precision is lost.New header:
One formatting source
getExplainTableRow(node, hasAnalyzeData, nodeMetrics)inpackages/explain/src/plan.tsreturns the raw values for one row: costs, rows, self time, estimate gap and filter. It also hides measured values when the plan has no ANALYZE data.getExplainTableRows(used by the CSV) andExplainTableView'sTreeRows(the screen) both call it. Each side only decides how to display the numbers (abbreviated on screen, plain in the file).getRowEstimateGap(node)replaces the privategetMismatchMagnitudeand the two inline copies of the "ratio or its inverse" maths. The amber highlight in the table now readsgap >= 4, which is the same condition as the oldratio >= 4 || ratio <= 0.25.index.ts, so the public API does not grow.ExplainTableRowDatachanges shape (costbecomesstartupCostandtotalCost). It was added in feat(explain): export complete EXPLAIN table as CSV (#1163) #1184 and has not been published to npm yet (the latest release, 0.2.0, came before it).Feedback
showToast(..., { kind: "success" })replaces the modalshowAlert.exportCsvErrorstring, with the reason fromtoErrorMessage(err)as the message (for examplepermission denied, or a plain string rejected by Tauri). It usesduration: 0, so it stays until dismissed and the reason can be read and reported.Connections.tsxdoes the same for its error toasts. The error is still logged to the console.downloadTextFilewith the platform fromusePlatformCapabilities, so it works in the desktop app and intabularis web.CRLF
\r\n. Line breaks inside quoted fields (for example a multi-line filter) are left as they are, which RFC 4180 allows.Cleanups
<table>block is no longer needed: Prettier onmain(chore: format the codebase with Prettier and tidy the project structure #1247) now formats it.editor.visualExplain.tableTitleis now "実行計画ツリー".How tested
pnpm typecheckandpnpm typecheck:explain: clean.pnpm lint: clean (ESLint, Prettier check and the theme token check).pnpm test run: 456 files, 7190 tests. All pass except 5 inweb-ui-project/tests/runWebUiTasks.test.mjs, which fail the same way onmainlocally.packages/explain,npx vitest run: 11 files, 183 tests passed.New and updated tests:
packages/web-ui/tests/utils/explainTableExport.test.ts: the new header, CRLF on every record with no bare LF, numeric cost and gap values for estimated and analyzed plans, a startup cost of 0 kept as0, missing costs (SQLite-style), a total cost with no startup cost (MySQL-style), NaN and Infinity costs, the estimate gap left empty when estimates or actual rows are missing or zero, an overestimate rounded to3.333, quoting, the semicolon delimiter, very large, very small and negative costs written without exponent notation, and a cost of 2^53 + 2 keeping every digit.packages/explain/tests/plan.test.ts:getRowEstimateGapin both directions plus the null cases, andgetExplainTableRow(raw costs, ANALYZE gating, index and depth fallback, and that it matches the row fromgetExplainTableRows).packages/web-ui/tests/components/explain/ExplainTableView.test.tsx: the table shows the cost, rows, time and gap from the shared row, and-instead of0when a value is missing.packages/web-ui/tests/components/explain/VisualExplainView.test.tsx: through the platform download andwriteFile, as main's raw-export tests do. Success opens the save dialog withexplain-plan.csv, writes the CSV once and shows a toast, not an alert. Cancelling the dialog writes nothing and shows nothing. A write error shows a persistent error toast with the reason, and the button can be used again. A plain string rejection is shown as the reason.Checked in
tabularis web(server built with--no-default-features, local PostgreSQL 17, EXPLAIN ANALYZE, Table view → Export CSV): success shows the toast and downloadsexplain-plan.csvastext/csvwith CRLF records and plain numbers. A download error forced from the page shows the persistent error toast with the reason. In web mode the browser handles the save, so a cancel in the browser's own prompt can't be seen by the page (same as the raw-plan export). I haven't checked the desktop window by hand.Closes #1231