Spring 模型要使用多个表

Spring model to use multiple tables

我有一个数据库-table 包含 5000 万多行。通过索引,我将 selecting 单行的请求时间从 50 秒减少到 2-5 秒。因为我仍然需要检索多个单行。通过在仅包含上个月记录的视图上执行 select,我能够进一步减少(<500 毫秒)。
不幸的是,设备可能在上个月没有产生记录,但我仍然需要它的最新记录。

如果主 table 上没有结果,是否有可能告诉 spring mvc 到 "fallback" 到另一个 table?类似于:

@Entity
@Table
(
schema="tbl",
name="name_of_view_for_last_month",
fallbackname="name_of_actual_table"
)
select 
  case check.exists
  when 1 then check.id 
  when 0 then (select id 
               from name_of_actual_table
               where <condition to get single row>)
  end as result
from (
    select count(id) as exist, id
    from name_of_view_for_last_month last
    where <condition to get single row>) check

像上面描述的那样在 SQL 水平上解决它怎么样?

在 Spring 级别,您可以为完整数据 table 和月视图创建 2 个 dao 类。

在服务中调用 monthDataDao,如果没有返回任何内容,则使用相同的请求调用 fullDataDao