Skip to content

SQL editor: schema browser, Open in SQL Editor, cancel, date functions (2/4) - #122

Open
miguelnieto wants to merge 2 commits into
vlsi:mainfrom
miguelnieto:02_sql-editor
Open

miguelnieto wants to merge 2 commits into
vlsi:mainfrom
miguelnieto:02_sql-editor

Conversation

@miguelnieto

@miguelnieto miguelnieto commented Oct 17, 2026 •

Copy link
Copy Markdown

Summary

Brings the SQL editor pane up to the standard of MAT's own panes, and adds:

  • a schema browser;
  • "Open in SQL Editor" on MAT's object menus;
  • cancel for running queries;
  • date and time SQL functions.

Stacked on #121 (MAT 1.17 / Java 21 / Calcite 1.42). Until #121 is merged, this PR also shows its commit. Review only e1d5ea1, or see just this PR's changes. PR 3/3 (MCP server) builds on this one.

Editor

  • Right-click menu: Run, Explain, Undo/Redo, Cut/Copy/Paste, Delete, Select All and Toggle Comment.
  • Key bindings in their own context. F5 / Ctrl+Enter, F10, Ctrl+Space and Ctrl+/ are now workbench commands in a context that is a child of MAT's editor context. MAT binds F5, Ctrl+Enter and Ctrl+Space to its OQL commands, and before this change the workbench consumed those keys before the SQL editor saw them.
  • Theme colors for the syntax (Preferences › Appearance › Colors and Fonts), with defaults for the dark theme. Line numbers are readable in the dark theme.
  • "SQL Reference" tab: tables, virtual columns and functions open in a separate tab, so the current result stays open. The 30-line help comment the editor used to start with is now a short hint and a sample query.
  • Completion pops up after typing . or ", not only on Ctrl+Space.
  • Result rows show MAT's object icons.
  • Reopening a result from the navigation history restores its query and runs it again, as the OQL pane does.
  • Errors are underlined at the right place, also when a selection or Explain runs, and the underline is cleared by the next run.
  • Cancel works. Cancel in the Progress view, or closing the tab, stops a running query. The heap object scan checks a per-query flag, QueryCancellation. Calcite itself only checks for cancel between result rows, so an aggregation could not be stopped before.

Schema browser

A toolbar toggle shows a tree beside the editor, listing:

  • classes by package;
  • classes with their subclasses (instanceof);
  • thread stacks and functions.

Each class shows its columns and its this['@shallow'] / this['@retained'] sizes. Double-click inserts a name at the cursor, quoted where SQL needs it. The filter box lists matching tables; it is debounced and works from cached sorted names, so it stays fast on dumps with many classes.

Open in SQL Editor

"SQL › Open in SQL Editor" appears on the context menu of objects and classes in MAT's views (histogram, dominator tree, object lists, …). It adds a query for the selection to the SQL tab of the objects' own dump, selects it, and doesn't run it:

  • objects: selected by address, one statement per class;
  • a class row: all its instances;
  • a class row of a partial histogram (Show Retained Set, a dominator tree grouped by class): only that row's objects.

SQL

  • Date and time functions: toDateTime(x[, zone]), toEpochMillis, millisToDateTime, secondsToDateTime, toDuration.
    • They cover java.util.Date, java.sql.*, Calendar and the java.time types.
    • A Date changed with a deprecated setter, or a Calendar changed with set(...), can hold a stale time; these return null rather than a wrong time.
    • Durations don't overflow at Long.MAX_VALUE seconds.
  • instanceof."java.lang.ref.Reference" accepts a full class name as one identifier. Identifiers are quoted by Calcite's own reserved words, not only SQL-92's: java.lang.ref doesn't parse unquoted, because REF is reserved.
  • The SQL reference now uses instanceof.java.util.AbstractMap as its example. Heap dumps record superclasses but not interfaces, so instanceof.java.util.Map is always empty.
  • CALCITE-1.42-QUERIES.md explains what Calcite 1.37–1.42 adds for heap queries.

Fixes

  • Keys stopped working on GTK/Wayland. After a table result was shown, Backspace, Delete and the arrow keys were dropped, while letters still typed. MAT's "Retrieving view elements…" progress dialog opens and closes without getting focus, and SWT is then left with no active shell. The pane now reactivates the workbench window, which also fixes MAT's own OQL pane.
  • The editor jumped when a query ran while it was scrolled to the end. JFace briefly lays the editor out taller during a toolbar relayout, and StyledText scrolls to fill the space. The scroll position is now restored after such a transient resize.
  • Undo/Redo keys didn't work, and Cut/Copy could be disabled while text was selected.
  • Closing a tab cleaned up badly:
    • a query that finished afterwards failed on the disposed editor;
    • closing the tab while the editor had focus left its key bindings active and the Cut/Copy/Paste handlers pointing at the closed editor.
  • The pane leaked its title image and syntax colors.
  • Removed debug output printed on stdout on every result refresh.

Testing

  • ./mvnw verify with JDK 21: 69 tests pass, 1 skipped (@Ignore on main too). New tests cover the SQL generated for selections, the date functions, cancellation, result icons, instanceof names and reserved-word quoting.

  • Checked by hand in MAT 1.17.0 on Linux (GTK/Wayland):

    • error underlines for a selection and for Explain;
    • closing a tab while its query runs;
    • key bindings after closing a tab;
    • the schema filter;
    • "Open in SQL Editor" with two dumps open.

    Cancel from the Progress view is covered by a unit test only.

🤖 Generated with Claude Code

@miguelnieto
miguelnieto force-pushed the 02_sql-editor branch 2 times, most recently from 58c3f0d to f54a26e Compare October 17, 2026 01:21
@miguelnieto miguelnieto changed the title SQL editor: schema browser, Open in SQL Editor, cancel, date functions (2/3) SQL editor: schema browser, Open in SQL Editor, cancel, date functions (2/4) Nov 7, 2026
miguelnieto and others added 2 commits November 7, 2026 16:45
BREAKING: requires MAT 1.17.0+ and Java 21. org.eclipse.mat.api 1.17.0
declares Bundle-RequiredExecutionEnvironment: JavaSE-21, so the execution
environment cannot go lower. Users on older MAT must stay on 1.6.x.

Platform
- Target platform moved from Eclipse 2022-12 to Eclipse 4.40, matching the
  Eclipse release MAT 1.17.0 builds against.
- MAT bundles come from the MAT 1.17.0 update site rather than an Eclipse
  simultaneous release, so the MAT API version matches the MAT users run.
  Only the units this plugin needs are listed; the full
  org.eclipse.mat.feature.feature.group would drag in mat.chart and
  therefore BIRT and Rhino, which are unused.
- Java 21: BREE, executionEnvironment, compiler source/target, CI matrix,
  README requirements.

Calcite 1.36 -> 1.42.0
- Aligned Calcite/Guava versions between MatCalcitePlugin/pom.xml and
  MatCalciteTargetPlatform.target (Guava 33.7.2-jre in both, after
  Renovate updated the pom only). They had drifted apart (1.41.0 vs 1.36.0)
  because Renovate only updates poms, not Tycho target definitions.
- Avatica 1.29.0 instead of the 1.28.0 Calcite 1.42.0 asks for: Avatica
  before 1.29.0 has CVE-2026-70410 (unsafe reflection in plugin
  instantiation, CVSS 8.8). Declared before calcite-core so Maven compiles
  against the Jackson 2.22.2 it brings, which the target ships.
- Added httpclient5/httpcore5 (new Avatica 1.28 dependencies) and
  org.jooq:joou-java-6 to the target platform and to Import-Package. Without
  them: NoClassDefFoundError for org/apache/hc/core5/util/Timeout and
  org/joou/UInteger.
- Excluded jakarta.transaction:jakarta.transaction-api from commons-dbcp2:
  it has an unsatisfiable Import-Package (javax.enterprise.context) and
  blocked geronimo-jta_1.1_spec from supplying javax.transaction.

ORDER BY and joins on heap objects
- Calcite 1.37+ sorts Map-typed values with Functions.compareMaps(), which
  calls entrySet(); HeapReference is a Map only for this['field'] and threw
  from entrySet(), so every ORDER BY over a heap object failed. entrySet()
  now returns one entry that orders like compareTo.
- Calcite sorts merge-join inputs through entrySet() but merges them with
  compareTo, so both must give the same order, or matches are dropped (the
  class/class loader join counted 469 instead of 985). Both now order by
  address, which is also constant time: ordering by label rebuilt the label
  on every comparison (ORDER BY this on 4M objects: about 2 min vs 10 s).
  ORDER BY toString(this) gives label order.

SQL functions
- getHexAddress(x): the object address as 0x..., as MAT shows it.
- getDominator(x) returned an error for objects dominated by the virtual
  root; it now returns null.

Tests
- testStackTraces tolerates MAT's own stack frame formatting, which changed
  in MAT commit 0c72944e ("Bug 581644"): "(Native Method)" became
  "(Object.java(Native Method))".
- New: ORDER BY this in both directions, a merge join over a strict subset,
  the class/class loader join phrased three ways (985 each).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r, date functions

Editor
- Right-click menu (Run, Explain, Undo/Redo, Cut/Copy/Paste, Delete, Select
  All, Toggle Comment); keys are workbench commands in their own context, so
  F5, Ctrl+Enter and Ctrl+Space no longer go to MAT's OQL commands.
- Schema browser beside the editor: classes by package, instanceof, thread
  stacks and functions, with columns and sizes; double-click inserts the
  name, quoted where SQL needs it. The filter is debounced and uses cached
  sorted names.
- "SQL Reference" tab; theme colors (with dark theme defaults); completion
  pops up after '.' and '"'; object icons in results; navigation history
  restores and reruns a query.
- Error underline at the right place for a selection and for Explain, and
  cleared on the next run. Cancel in the progress view and closing the tab
  stop a running query (QueryCancellation, checked by the heap scan).
- Fixes: keys lost after a table result on GTK/Wayland (no active shell),
  editor scroll jump on a transient resize, Undo/Redo keys, leaked title
  image and colors, closed-tab cleanup, debug output on stdout.

Open in SQL Editor
- On MAT's object menus: a query for the selected objects (by address, one
  statement per class) or for a class row (all instances, or the row's
  objects for a partial histogram), added to the SQL tab of the objects' own
  dump.

SQL
- Date and time functions: toDateTime, toEpochMillis, millisToDateTime,
  secondsToDateTime, toDuration.
- instanceof."java.lang.ref.Reference" (full class name as one identifier);
  identifiers quoted by Calcite's reserved words, not only SQL-92's.
- CALCITE-1.42-QUERIES.md: what Calcite 1.37-1.42 adds to heap queries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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