Asterisk realtime callerid support + optimisation

First of all i like t say , that i have made some upgrate to asterisk and now it can also check callerid while reading extensions from realtime.

And now i must say that i found maybe bug in asterisk.

His choosing of best extension is not optimal .

My example :

for example i have such extensions


If i make call to 11111 - asterisk will check the database and return only one extension 11111,1,Dial(SIP/${exten}) to asterisk , And a call will porceed.

If i make a call to number 10000 asterisk will try to find exact exten. But after that - it will load every extension . And engine will choose optimal.
It is not problem for those who have ont much extensions in realtime configuration . BUT. If you have about 5000 extensions you will have a problem . Because asterisl will load all extensions from database ( it takes time about 5-10 seconds ) , and only after that – the call will porceed.

I tryuing to make optimisation in work of realtime. If anyone can help me . It will be pleasant for me.

My icq is 73493998 .
Let`s make asterisk better.