0
Dear Members, Suppose a graph is registered in two ways:
TABELA_A:
T | V1 | V2
1 | 1 | 2
2 | 2 | 3
3 | 2 | 4
4 | 4 | 5
TABELA_B:
T | V1 | V2
1 | 1 | 2
2 | 2 | 3
3 | 4 | 2 <====OBSERVEM QUE AQUI INVERTI OS VÉRTICES
4 | 4 | 5
That said, I need to perform the reading so that I scan all the "T" edges, but without looping or even if it occurs reading a stretch more than once.
For table A, the solution is simple:
SELECT v1,
v2
FROM tabela_a
CONNECT BY NOCYCLE PRIOR b2 = b1
On the other hand, the solution for TABELA_B becomes a little more complex. Mainly for analogous situations but with an excessively larger amount of edges. That is why I emphasize the need to read only once each passage ("edge"). A "grotesque" but effective solution for cases with few edges that I proposed, boils down to:
SELECT DISTINCT <== observe que tentei o DISTINCT,
mas sem efeitos eficientes v1,
v2
FROM tabela_a connect BY nocycle (prior b2 = b1)
OR prior b2 = b2 )
OR prior b1 = b2 )
OR (prior b1 = b1 )
The example presented is merely illustrative. The case I have at hand consists of more than 10,000 lines and with these cases of "inversion". Nothing less, I need to scan the graph following the logic of the DFS search algorithm (Depth first search), similar to what occurs in reading TABELA_A, but with possible inversions as shown. The solution to read TABELA_B is bad, because it reads the same stretch numerous times and then filters the singular (through DISTINCT). This is bad because it makes the process too slow.
Try a Union select t,va,Vb from(select t,v1 va,v2 Vb from table Union select t,v2 va,v1vb from table , connect by nesra table.
– Motta