Dear, 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 read so that I scan all the "T" edges, but without looping or even reading a portion 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 to TABLE_B becomes a bit more complex. Especially for analogous situations but with an excessively large amount of edges. For this reason, I stress the need to read each section only once ("edge"). A "grotesque" but effective solution for cases with few edges that it proposes, it is summarized as:
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 in my hands 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 (depth first search) algorithm, similar to what happens in reading TABLE_A, but with possible inversions as presented. The solution to read TABLE_B is bad, because it reads the same passage countless times and then filters the singles (through DISTINCT). This is bad as it makes the process very slow.