内部联接查询-Oracle

时间:2018-07-12 10:04:15

标签: sql oracle

我正在尝试在UAT中运行以下查询,这给了我非常快速的结果,但是 投入生产后,我们有大约1000万条记录查询花费的时间太长。有什么更好的方法吗?

SELECT w.row_id,
       w.field_1,
       w.field_2,
       w.field_3,
       b.row_id,
       b.field_1,
       b.field_2,
       b.field_3
  FROM si.table1 w
       INNER JOIN si.table1 b
          ON     w.par_row_id = b.par_row_id
             AND w.field_1 = b.field_1
             AND w.field_3 = b.field_3
 WHERE     w.field4 = 'TEXT1'
       AND b.field4 = 'TEXT1'
       AND UPPER (w.field_2) = 'TEXT2'
       AND UPPER (b.field_2) = 'TEXT3'

1 个答案:

答案 0 :(得分:0)

对于此查询:

var items = Regex.Split("4M1L1T3", @"(?<=[A-Za-z])(?=\d+[A-Za-z])");
foreach (var item in items)
{
    Console.WriteLine(item.ToString());
}

4M
1L
1T3

您需要一个索引策略。我会去SELECT . . . FROM si.table1 w INNER JOIN si.table1 b ON w.par_row_id = b.par_row_id AND w.field_1 = b.field_1 AND w.field_3 = b.field_3 AND w.field4 = b.field4 WHERE w.field4 = 'TEXT1' AND UPPER(w.field_2) = 'TEXT2' AND UPPER(b.field_2) = 'TEXT3'; table1(field4, upper(field_2), par_row_id, field_1, field_3, field4)