I have two tables:
t1: f1, f2, f3, f4, rowid_t2, sts
t2: f1, f2, f3, f4, sts
with different amounts of records that exceeds 10 millions.
I need to match them using f1
, f2
and f3
of each table as the keys, the relation is
that one record of t1 can match with one record in t2 or many records of t1 can match with one record in t2, the matching depends on the conditions indicated in the three operations below.
I need to perform the next matching operations:
a) If t1.f1 = t2.f1
and t1.f2 = t2.f2
and t1.f3 = t2.f3
then I must update the rowid of t2
into t1.rowid_t2
and save t1.sts=1
, t2.sts=1
in the records matched.
b) If t1.f1 = t2.f1
and t1.f2 = t2.f2
and t1.f3 <> t2.f3
then I must update the rowid of t2
into rowid_t2
and save t1.sts=2
, t2.sts=2
in the records matched.
c) If t1.f1 = t2.f1
and t1.f2 <> t2.f2
and t1.f3 <> t2.f3
then I must update the rowid of T2
into rowid_t2 and save t1.sts=3
, t2.sts=3
in the records matched.
I have 2 questions:
Can I solve the problem using
UPDATE
? If yes, it would be nice if you can show me the solution only for a)How many indexes should I create to optimize the necessary UPDATEs and SELECTs for the three operations?
Many thanks!!