Skip to content
Advertisement

Tag: query-optimization

Simplifying SELECT statement

so I have a statement I believe should work… However it feels pretty suboptimal and I can’t for the life of me figure out how to optimise it. I have the following tables: Transactions [Id] is PRIMARY KEY IDENTITY [Hash] has a UNIQUE constraint [BlockNumber] has an Index Transfers [Id] is PRIMARY KEY IDENTITY [TransactionId] is a Foreign Key referencing

Select all groups that contain all specified values in a certain column

Say I have the following table: CaseRef NotificationReason NotificationDate 123 SCHEDULED 2022-01-01 234 SCHEDULED 2022-01-02 312 SCHEDULED 2022-01-01 123 RESCHEDULED 2022-01-02 123 DECIDED 2022-01-03 234 DECIDED 2022-01-02 If I want to return only rows that have a CaseRef that has both a SCHEDULED and a DECIDED value in NotificationReason. CaseRef NotificationReason NotificationDate 234 SCHEDULED 2022-01-02 234 DECIDED 2022-01-02 123 SCHEDULED

Why does this SQL query get stuck in an endless loop?

The following PostgreSQL query gets stuck loading endlessly. I know correlated sub-queries can take long, but a SELECT using the same parameters worked quickly and returned the desired results. And I have a small data set that I let run for an entire day just to make sure it wouldn’t eventually work with time. Table_A uses hierarchical data structures and

How can I replace this correlated subquery within a function call?

Given the following tables buckets points And the following query Output How can I remove the correlated sub-query to improve the performance? Currently ~280,000 points * ~650 buckets = ~180,000,000 loops = very slow! Basically I want to remove the correlated sub-query and apply the width_bucket function only once per unique metric_id in buckets, so that the performance is improved