@@ -90,25 +90,25 @@ func runMutation(ctx context.Context, edge *pb.DirectedEdge, txn *posting.Txn) e
9090 // The following is a performance optimization which allows us to not read a posting list from
9191 // disk. We calculate this based on how AddMutationWithIndex works. The general idea is that if
9292 // we're not using the read posting list, we don't need to retrieve it. We need the posting list
93- // if we're doing indexing or count index or enforcing single UID, etc. In other cases, we can
94- // just create a posting list facade in memory and use it to store the delta in Badger. Later,
95- // the rollup operation would consolidate all these deltas into a posting list.
93+ // if we're doing count index or delete operation. For scalar predicates, we just get the last item merged.
94+ // In other cases, we can just create a posting list facade in memory and use it to store the delta in Badger.
95+ // Later, the rollup operation would consolidate all these deltas into a posting list.
96+ isList := su .GetList ()
9697 var getFn func (key []byte ) (* posting.List , error )
9798 switch {
98- case len (su . GetTokenizer ()) > 0 || su . GetCount () :
99- // Any index or count index.
100- getFn = txn .Get
101- case su . GetValueType () == pb . Posting_UID && ! su .GetList ():
102- // Single UID, not a list.
99+ case len (edge . Lang ) == 0 && ! isList :
100+ // Scalar Predicates, without lang
101+ getFn = txn .GetScalarList
102+ case len ( edge . Lang ) > 0 || su .GetCount ():
103+ // Language or Count Index
103104 getFn = txn .Get
104105 case edge .Op == pb .DirectedEdge_DEL :
105106 // Covers various delete cases to keep things simple.
106107 getFn = txn .Get
107108 default :
108- // Reverse index doesn't need the posting list to be read. We already covered count index,
109- // single uid and delete all above.
110- // Values, whether single or list, don't need to be read.
111- // Uid list doesn't need to be read.
109+ // Only count index needs to be read. For other indexes on list, we don't need to read any data.
110+ // For indexes on scalar prediactes, only the last element needs to be left.
111+ // Delete cases covered above.
112112 getFn = txn .GetFromDelta
113113 }
114114
0 commit comments