Talk:How Call Routing works
From AstBillWiki
SELECT name trunkname, pattern, trunkcost cost_metric,costplan FROM astroute, asv_trunk_dialplan2 trunk WHERE astroute.trunk = trunk.name and '44207055XXXX' LIKE CONCAT(pattern,"%") and usagecount < maxusage and astroute.trunk <> 'Local' ORDER BY patternlen, LENGTH( pattern ) DESC, trunk.trunkcost, costplan;
is faster
SELECT astroute.trunk INTO strunk FROM astroute, asv_trunk_dialplan2 trunk,
(SELECT trunk, MIN(patternlen) AS patternlen,
MAX(LENGTH(pattern)) AS len FROM astroute, asv_trunk_dialplan2 trunk
WHERE astroute.trunk = trunk.name and
phone LIKE CONCAT(pattern,"%") AND usagecount < maxusage
AND astroute.trunk <> 'Local'
GROUP BY trunk
ORDER BY patternlen, LENGTH( pattern ) DESC) AS
trunk_pattern
WHERE astroute.trunk = trunk_pattern.trunk AND astroute.trunk = trunk.name
AND phone LIKE CONCAT(pattern,"%") AND usagecount < maxusage
AND trunk_pattern.patternlen = astroute.patternlen AND trunk_pattern.len = LENGTH( pattern )
ORDER BY cost+trunk.trunkcost/100, costplan LIMIT 1;
We've added this query (to GetRateTrunk) in order to get true (but weighted) LCR. It still doesn't handle the issue of failure of 1 trunk being backed up.
