This is a common architectural challenge when implementing CDS view security at enterprise scale. Let me share a comprehensive performance optimization strategy:
CDS View Security Architecture:
CDS DCL (Data Control Language) provides elegant row-level filtering but introduces authorization joins that HANA’s cost-based optimizer struggles with. The core issue: authorization resolution happens at query runtime, preventing effective query plan caching and index utilization. Your 3-4x performance degradation is typical for naive DCL implementations on large datasets.
Row-Level Filtering Optimization:
The T77UA organizational assignment table is your bottleneck. With 500K+ rows, every authorization join becomes expensive. Implement a three-tier optimization strategy:
-
Authorization Context Caching: Create a custom HANA table (Z_USER_COSTCTR_CACHE) that stores flattened user-to-cost-center mappings. Refresh this daily via background job. Your CDS view joins to this smaller, indexed table instead of T77UA. This reduces authorization join from 500K rows to ~50-100 rows per user.
-
Partition-Aware Design: Restructure your cost accounting CDS view to leverage HANA partitioning. Partition fact tables by fiscal period (monthly or quarterly). Add partition pruning hints in your CDS view using @AbapCatalog.sqlViewAppendName. This ensures queries only scan relevant partitions.
-
Authorization-Aware Indexes: Create composite indexes that combine authorization fields with query filters. For example: INDEX on (KOKRS, KOSTL, GJAHR, POPER) where KOKRS and KOSTL are authorization fields. This allows index-only scans for typical period-based reports.
Query Optimization Techniques:
Your database indexing on KOSTL alone isn’t sufficient. HANA’s optimizer needs multi-column statistics that span authorization and business dimensions. Run HANA statistics update on your fact tables with explicit column groups: KOSTL + GJAHR + POPER. This improves cardinality estimation for authorization-filtered queries.
Implement CDS view annotations that guide HANA optimizer:
@Analytics.query: true
@Analytics.dataCategory: #CUBE
@ClientHandling.algorithm: #SESSION_VARIABLE
These annotations enable result set caching and session-based optimization.
Performance Monitoring Deep Dive:
Your 8-12 second queries suggest multiple issues. Analyze HANA SQL trace (transaction SQLM) to identify:
- Join order: Authorization joins should happen first (most selective)
- Aggregation timing: Push aggregations after authorization filters
- Column store unloads: Ensure frequently accessed columns stay memory-resident
Use HANA’s Plan Viz (EXPLAIN PLAN) to verify authorization filters are pushed down before expensive operations like aggregation or sorting.
Database Indexing Strategy:
Create specialized indexes for authorization patterns:
- Covering index: (USER_ID, KOSTL, VALID_FROM, VALID_TO) on Z_USER_COSTCTR_CACHE
- Composite index: (KOSTL, BUKRS, GJAHR) on cost center fact table
- Partition-local indexes on time-series columns
Avoid generic indexes on single columns - they’re ineffective for authorization-filtered queries.
Balancing Security and Performance:
The materialization approach (pre-calculating authorized result sets) works for static reports but breaks real-time requirements. Instead, implement hybrid strategy:
-
Real-time dashboards: Use parameterized CDS views that accept pre-resolved cost center lists from ABAP layer. ABAP code resolves authorization once per session, passes list to CDS via parameters. This eliminates authorization joins entirely for dashboard queries.
-
Batch reports: Use full DCL with optimized authorization cache. Nightly refresh ensures authorization data is current.
-
Ad-hoc queries: Implement query result caching at application layer (SAP Gateway cache, Redis). Cache authorized result sets for 15-30 minutes based on user + query parameters.
Alternative Architecture - Authorization Views:
Consider splitting your CDS view into two layers:
- Base view (no DCL): Contains all data, unrestricted
- Authorization view (with DCL): Thin wrapper that applies row-level security
Application layer can choose which view to use based on user context. Power users with broad authorization use base view for maximum performance. Restricted users use authorization view.
Scaling Considerations:
For organizations with complex hierarchies (>100K cost centers), even optimized DCL hits limits. At that scale, consider authorization-aware partitioning: physically separate data by organizational unit (holding company, region) and route users to appropriate HANA tenant. This eliminates cross-tenant authorization checks entirely.
Implement these optimizations iteratively, measuring impact at each step. Target 2-3 second query response for typical dashboard queries - achievable with proper authorization caching and index strategy.