Preventing "deleted" nodes from appearing in search queries

I have been trying to implement “deletion” for nodes that satisfy a certain criterion. I delete a node by removing incoming edges to and outgoing edges from it.

My understanding is that, by dgraph design, the node itself and the values it contains continue to exist after these edges have been removed. The values can be set to null, but they continue to consume memory. Please correct me if this understanding is wrong.

I have two questions. Firstly, these nodes continue to be retrieved by queries, which I would like to avoid. I can accomplish this by setting an additional field in each node, which signifies whether it has been deleted. Is there another way to do this?

Secondly, what exactly happens when a uid is “recycled”? I assume this means that this uid is now available to be assigned to another node. But, what exactly happens to the node whose uid is recycled?

Also, I would highly appreciate some sample syntax to recycle a node using the go client – I didn’t see any syntax to do this on the website.

Thanks!

I don’t think we recycle UIDs. UIDs are picked up from a 64 bit space which is large enough to not be recycled.

For the first question, as far as I know, we only store edges (RDFs) in Dgraph. Once all the information about UID is deleted (i.e. all the predicates attached to a UID are deleted), UID doesn’t exist any more in the system. If you have any example, where you see deleted UIDs in the result, let us know.

Querying for not existing UIDs will return those UIDs as well, even the deleted one

{
  result(func: uid(0x0)) {
    uid
    name
  }
}

as a response you will get

{
  "data": {
    "result": [
      {
        "uid": "0x0"
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 59539,
      "processing_ns": 159759,
      "encoding_ns": 4887,
      "total_ns": 304078
    },
    "txn": {
      "start_ts": 10279
    },
    "metrics": {
      "num_uids": {
        "": 1,
        "name": 1,
        "uid": 1
      }
    }
  }
}

yeah, the uid function doesn’t actually do anything. It returns what UIDs that are provided in the argument. But if you query for any other predicates than UID, you won’t see those results.

In that case, as you said, keeping a predicate existence of which tells you whether the UID exists, seems like a good solution to me.