Skip to content

Useful stuff for developers

Kristian Larsson edited this page Mar 18, 2014 · 1 revision

Check that indent is correct:

SELECT * FROM (
        SELECT vrf_id,
                indent,
                (SELECT COUNT(1) FROM ip_net_plan AS inp2 WHERE inp2.vrf_id = inp.vrf_id AND iprange(prefix) >> iprange(inp.prefix)) AS calc_indent,
                prefix
        FROM ip_net_plan AS inp
        ORDER BY vrf_id, prefix
        ) AS a
WHERE indent != calc_indent;

Recalculate indent on all prefixes:

UPDATE ip_net_plan AS inp_u
SET indent = inp_wrong.calc_indent
FROM (SELECT * FROM (
                SELECT id,
                        vrf_id,
                        indent,
                        (SELECT COUNT(1) FROM ip_net_plan AS inp2 WHERE inp2.vrf_id = inp.vrf_id AND iprange(prefix) >> iprange(inp.prefix)) AS calc_indent,
                        prefix
                FROM ip_net_plan AS inp
                ORDER BY vrf_id, prefix
                ) AS a
        WHERE indent != calc_indent
) AS inp_wrong WHERE inp_u.id = inp_wrong.id AND inp_wrong.indent != inp_wrong.calc_indent;