Detect longest chains and circles in the dupe graph (NOT READY YET)

1

Please login or register to vote for this query.

(click on this box to dismiss)

NOT READY YET

Poker Meta

Q&A for serious players and enthusiasts of poker

CREATE TABLE #Dupes (
  DupeId INT,
  OrigId INT,
  Level INT,
  InCircle BIT
);

CREATE INDEX DupesPk ON #Dupes(Level, InCircle);

INSERT INTO #Dupes
SELECT
  PostId AS DupeId,
  RelatedPostId AS OrigId,
  1 AS Level,
  0 AS InCircle
FROM PostLinks
WHERE LinkTypeId = 3

DECLARE @CurLevel INT = 1;

WHILE 1 = 1
BEGIN
  IF
    (SELECT COUNT(*) FROM #Dupes WHERE Level = @CurLevel) = 0
    OR
    @CurLevel = 10
  BEGIN
    BREAK;
  END;

  UPDATE #Dupes
  SET InCircle = 1
  WHERE DupeId = OrigId AND Level = @CurLevel

  INSERT INTO #Dupes
  SELECT Cur.DupeId, Nxt.OrigId, @CurLevel + 1 AS Level, 0 AS InCircle
  FROM #Dupes Cur, #Dupes Nxt
  WHERE
    Cur.Level = @CurLevel
    AND
    Cur.InCircle = 0
    AND
    Nxt.InCircle = 0
    AND
    Cur.OrigId = Nxt.DupeId;
  
  PRINT 'RowCount: ' + CAST(@@ROWCOUNT AS VARCHAR(MAX))
    + ' CurLevel: ' + CAST(@CurLevel AS VARCHAR(MAX));
  
  SET @CurLevel = @CurLevel + 1;
END;

SELECT OrigId AS [Post Link], *
FROM #Dupes
WHERE Level = 7

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results