How Neo4j search data if i search nodes with the label.
If i use profile/explain the operator that shows was NodeByLabelScan.
My specific question here is, does Neo4j maintain additional storage(or any special kind of indexed data) so that, while processing query uses that data to effectively search nodes.
I believe there are lists of nodes organized by Labels. (Since a Node can have multiple Labels, a Node can belong in multiple lists.). So when you try to match by label, it scans a subset of all Nodes, making that quicker.
This video explains a lot of interesting internals of Neo4J:
Thank you Clem,
On indexes i was clear that it has additional cost to maintain index data (additional memory) that helps to find/search the data.
My question is more specific to LABEL , how LABELS helps query engine to search data efficiently/quickly. Let me rephrase the question again: On creating LABEL what all the changes(extra memory or something else created behind the scene) that helps query engine to get data quickly.
I'm afraid I didn't make myself clear enough.... Sorry.
There is a (hidden) collection (set) per Label of all Nodes that have that Label. (Nodes can have 0 or 1 or more Labels). When you do MATCH(n:LabelA), the MATCH scans through the list of nodes that have LabelA.
If you add LabelA to a Node, that just means the Node gets added to the list of all nodes associated with LabelA. Similarly if remove LabelA from a Node, that Node gets from from the list.
Of course, this all occurs behind the scenes so you don't see it directly.
If you do MATCH(n) that matches against all nodes, which is an expensive operation.
A similar thing occurs for Relationship Labels.
The trick is to make this as efficient as possible. One way is to keep these lists in memory so that they don't have to be fetched from disk.
There's a Neo4J video that explains this better somewhere, but I forget where.