Skip to content

Instantly share code, notes, and snippets.

@n5i
Last active November 5, 2018 16:54
Show Gist options
  • Save n5i/1acb42005a4412ab7a15087ac7dc4290 to your computer and use it in GitHub Desktop.
Save n5i/1acb42005a4412ab7a15087ac7dc4290 to your computer and use it in GitHub Desktop.
neo4j sorting
// Add index
CREATE INDEX ON :Var(value)
// Polulate data
WITH ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t","u","v","w", "z", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] AS R
UNWIND range(0,1000000) AS d
WITH R,
toInteger(rand()*36) AS i1,
toInteger(rand()*36) AS i2,
toInteger(rand()*36) AS i3,
toInteger(rand()*36) AS i4,
toInteger(rand()*36) AS i5,
toInteger(rand()*36) AS i6,
toInteger(rand()*36) AS i7,
toInteger(rand()*36) AS i8,
toInteger(rand()*36) AS i9,
toInteger(rand()*36) AS i10,
toInteger(rand()*36) AS i11,
toInteger(rand()*36) AS i12,
toInteger(rand()*36) AS i13,
toInteger(rand()*36) AS i14,
toInteger(rand()*36) AS i15,
toInteger(rand()*36) AS i16,
toInteger(rand()*36) AS i17,
toInteger(rand()*36) AS i18,
toInteger(rand()*36) AS i19,
toInteger(rand()*36) AS i20
WITH
R[i1] + R[i2] + R[i3] + R[i4] + R[i5] + R[i6] + R[i7] + R[i8] + R[i9] + R[i10] + R[i11] + R[i12] + R[i13] + R[i14] + R[i15] + R[i16] + R[i17] + R[i18] + R[i19] + R[i20] + R[i20] + R[i19] + R[i18] + R[i17] + R[i16] + R[i15] + R[i14] + R[i13] +R[i12] + R[i11] + R[i10] +R[i9] + R[i8] + R[i7] + R[i6] + R[i5] + R[i4] + R[i3] + R[i2] + R[i1] AS Val
CREATE (:Var{value:Val})
// Select sorted
MATCH (v:Var)
RETURN v.value
ORDER BY v.value
SKIP 5000000
LIMIT 10
# Started streaming 10 records after 1 ms and completed after 17899 ms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment