Вопрос

Greetings Overflowers,

Is there an SQL DBMS that allows me to create an indexed view in which I can insert new rows without modifying the original tables of the view? I will need to query this view after performing the in-view-only inserts. If the answer is no, what other methods can do the job? I simply want to merge a set of rows that comes from another server with the set of rows in the created view -in a specific order- to be able to perform fast queries against the merged set, ie the indexed view, without having to persist the received set in disk. I am not sure if using in-memory database would perform well as the merged sets grow ridiculously?

What do you think guys?

Kind regards

Это было полезно?

Решение

Well, there's no supported way to do that, since the view has to be based on some table(s).

Besides that, indexed views are not meant to be used like that. You don't have to push any data into the index view thinking that you will make data retrieval faster.

I suggest you keep your view just the way it is. And then have a staging table, with the proper indexes created on it, in which you insert the data coming from the external system.

The staging table should be truncated anytime you want to get rid of the data (so right before you're inserting new data). That should be done in a SNAPSHOT ISOLATION transaction, so your existing queries don't read dirty data, or deadlock.

Then you have two options:

  1. Use an UNION ALL clause to merge the results from the view and the staging table when you want to retrieve your data.
  2. If the staging table shouldn't be merged, but inner joined, then you perhaps can integrate it in the indexed view.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top