how to make selecting random rows in oracle faster with table with millions of rows

前端 未结 7 1146
后悔当初
后悔当初 2021-02-13 11:25

Is there a way to make selecting random rows faster in oracle with a table that has million of rows. I tried to use sample(x) and dbms_random.value and its taking a long time to

7条回答
  •  误落风尘
    2021-02-13 11:59

    Start with Adam's answer first, but if SAMPLE just isn't fast enough, even with the ROWNUM optimization, you can use block samples:

    ....FROM [table] SAMPLE BLOCK (0.01)
    

    This applies the sampling at the block level instead of for each row. This does mean that it can skip large swathes of data from the table so the sample percent will be very rough. It's not unusual for a SAMPLE BLOCK with a low percentage to return zero rows.

提交回复
热议问题