start transaction;

select nodeLink_UpdateStart();

drop temporary table if exists streetless;

create temporary table streetless(id int not null primary key)
select loc.id
from tagV loc
join nodeLinkTypeT nlt on nlt.isDefault = 'y'
where loc.typeCode = 'locality'
    and not exists(
        select 1 
        from nodeLinkT link 
        join tagV street on link.dstNodeId = street.id
            and street.typeCode = 'street'
        where nlt.id = link.nodeLinkTypeId
            and link.srcNodeId = loc.id 
            and link.metric = 1)
limit 45;

insert zzzDevNullT(n)
select
    nodeLink_Relink(null, s.id, tag_CreateDef(null, 'street', '-'))
from streetless s;
    
select nodeLink_UpdateEnd();

commit;
