There are two servers. The first is an ERP production system. The second is a BI server for heavy analytic queries. We update the BI server daily with backups. However, this is not enough, some users want to see that their data changes more often than the next day. I do not have access to the ERP server and can do nothing but request backups or replicas.
Before you start requesting replication. I want to understand whether it is possible to use subscriber triggers to process not all data, but changed data. There is an ETL process that speeds up the execution of certain queries (indexing, conversion, etc.). Triggers should do the trick, but I can’t find a way to use them only on the subscriber side. The ERP system does not allow changes at the database level. Thus, the subscriber base seems to be suitable for triggers (they do not affect the performance of the ERP server). However, I cannot find a way to configure them. Processing all the data is crazy overhead.
Use case . A simplified example, let's say we have two replicated tables:
+------------+-------------+--------+ | dt | customer_id | amount | +------------+-------------+--------+ | 2017-01-01 | 1 | 234 | | 2017-01-02 | 1 | 123 | +------------+-------------+--------+ +------------+-------------+------------+------------+ | manager_id | customer_id | date_from | date_to | +------------+-------------+------------+------------+ | 1 | 1 | 2017-01-01 | 2017-01-02 | | 2 | 1 | 2017-01-02 | null | +------------+-------------+------------+------------+
I need to convert them to the following indexed table:
+----------+-------------+------------+--------+ | dt_id | customer_id | manager_id | amount | +----------+-------------+------------+--------+ | 20170101 | 1 | 1 | 234 | | 20170102 | 1 | 2 | 123 | +----------+-------------+------------+--------+
So, I created another database where I store the table above. Now, to update the table, I have to truncate it and insert all the data again. I can join them all to check the differences, but this is too heavy for large tables. A trigger helps track only record changes. The first input table can use a trigger:
create trigger SaleInsert on Table1 after insert begin insert into NewDB..IndexedTable select //some transformation from inserted left join Table2 on Table1.customer_id = Table2.customer_id and Table1.dt >= Table2.date_from and Table1.dt < Table2.date_to end
The same idea for updating, deleting, a similar approach for the second table. I could automatically update DWH with slight delays. Yes, I expect performance delays for busy databases. Theoretically, it should work smoothly on servers with the same configurations.
But, again, there are no triggers on the subscriber side. Any ideas, alternatives?