문제

I have a PostgreSQL table, Prices, with the columns:

  • price (Decimal)
  • product_id (Int)

There are also created_at and updated_at columns.

Prices get updated regularly and I keep old prices in the table. For a given product, the last price in the table is the current price.

What is the most efficient way to get the last price for a specific product:

  • Index product_id and query for the last record
  • Add a third column active (Boolean) to mark the latest price and create a composite index (product_id and active)
  • Or something else?

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 dba.stackexchange
scroll top