Skip to content

perf(database): check table, view and materialized view access in one pass - #45887

Open
no-hup wants to merge 1 commit into
apache:masterfrom
no-hup:perf/tables-one-permission-pass
Open

no-hup wants to merge 1 commit into
apache:masterfrom
no-hup:perf/tables-one-permission-pass

Conversation

@no-hup

@no-hup no-hup commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

Listing a schema's tables (GET /api/v1/database/<id>/tables/) calls get_datasources_accessible_by_user once for tables, once for views and once for materialized views. Each call looks up the user's database, catalog, schema and dataset grants again, so for a user with dataset-level access the same permission queries run three times.

This filters all three lists in one call and splits the result. The filter works per name, so the output doesn't change.

For a user with datasource_access on one table, one listing went from 41 SQL statements to 23 (SQLite, counted with a before_cursor_execute listener).

SQL statements per listing
master 41
this branch 23

TESTING INSTRUCTIONS

pytest tests/unit_tests/commands/databases/tables_test.py — passes.

The existing tests mocked three calls; they now assert a single call with every name. The new test_tables_resolve_permissions_once runs the real filter and checks the grants are looked up once per listing. It fails on master (9 lookups instead of 3).

ruff check and ruff format --check are clean.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

… pass

TablesDatabaseCommand called get_datasources_accessible_by_user once per
list. Each call resolves the user's database, catalog, schema and
datasource grants from scratch, so listing a schema ran the same
permission queries three times. Filter the three lists with one call.

For a user with only dataset-level access, one table listing goes from
41 statements to 23 on SQLite, with the same result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 1ddc942196b9

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.71%. Comparing base (4e6d03b) to head (1ddc942).

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #45887       +/-   ##
===========================================
+ Coverage   65.62%   84.71%   +19.09%     
===========================================
  Files        3069     3069               
  Lines      205661   205665        +4     
  Branches    48336    48336               
===========================================
+ Hits       134955   174222    +39267     
+ Misses      67625    28150    -39475     
- Partials     3081     3293      +212     
Flag Coverage Δ
hive 34.51% <0.00%> (-0.01%) ⬇️
mysql 52.58% <100.00%> (+<0.01%) ⬆️
postgres 52.59% <100.00%> (+<0.01%) ⬆️
presto 36.24% <0.00%> (-0.01%) ⬇️
python 87.75% <100.00%> (+34.89%) ⬆️
sqlite 52.35% <100.00%> (+<0.01%) ⬆️
unit 82.49% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant