enhance:[Cherry-pick] forbid delete with always true expression (#32472) (#32495)

pr: https://github.com/milvus-io/milvus/pull/32472

Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>
This commit is contained in:
aoiasd 2024-04-23 17:45:27 +08:00 committed by GitHub
parent 2d5f674c78
commit deda656dcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View File

@ -300,11 +300,15 @@ func (dr *deleteRunner) Init(ctx context.Context) error {
}
func (dr *deleteRunner) Run(ctx context.Context) error {
plan, err := planparserv2.CreateRetrievePlan(dr.schema.CollectionSchema, dr.req.Expr)
plan, err := planparserv2.CreateRetrievePlan(dr.schema.CollectionSchema, dr.req.GetExpr())
if err != nil {
return fmt.Errorf("failed to create expr plan, expr = %s", dr.req.GetExpr())
}
if planparserv2.IsAlwaysTruePlan(plan) {
return merr.WrapErrParameterInvalidMsg("delete plan can't be empty or always true : %s", dr.req.GetExpr())
}
isSimple, pk, numRow := getPrimaryKeysFromPlan(dr.schema.CollectionSchema, plan)
if isSimple {
// if could get delete.primaryKeys from delete expr

View File

@ -517,6 +517,38 @@ func TestDeleteRunner_Run(t *testing.T) {
assert.Equal(t, int64(0), dr.result.DeleteCnt)
})
t.Run("delete with always true expression failed", func(t *testing.T) {
mockMgr := NewMockChannelsMgr(t)
lb := NewMockLBPolicy(t)
dr := deleteRunner{
chMgr: mockMgr,
schema: schema,
collectionID: collectionID,
partitionID: partitionID,
vChannels: channels,
tsoAllocatorIns: tsoAllocator,
idAllocator: idAllocator,
queue: queue.dmQueue,
lb: lb,
result: &milvuspb.MutationResult{
Status: merr.Success(),
IDs: &schemapb.IDs{
IdField: nil,
},
},
req: &milvuspb.DeleteRequest{
CollectionName: collectionName,
PartitionName: partitionName,
DbName: dbName,
Expr: " ",
},
}
assert.Error(t, dr.Run(context.Background()))
assert.Equal(t, int64(0), dr.result.DeleteCnt)
})
t.Run("complex delete query rpc failed", func(t *testing.T) {
mockMgr := NewMockChannelsMgr(t)
qn := mocks.NewMockQueryNodeClient(t)