Repository: vitessio/vitess
Pull request #6108 (2020-04-24 09:48:07)

Implement plan description for vindex_func

harshit-gangal: have conflicts

Patch:
diff --git a/go/vt/vtgate/engine/vindex_func.go b/go/vt/vtgate/engine/vindex_func.go
index c30d0bcd80..d301b238bb 100644
--- a/go/vt/vtgate/engine/vindex_func.go
+++ b/go/vt/vtgate/engine/vindex_func.go
@@ -181,5 +181,23 @@ func (vf *VindexFunc) buildRow(id sqltypes.Value, ksid []byte, kr *topodatapb.Ke
 }
 
 func (vf *VindexFunc) description() PrimitiveDescription {
-	return PrimitiveDescription{OperatorType: "vindexfunc - not implemented"}
+	fields := map[string]string{}
+	for _, field := range vf.Fields {
+		fields[field.Name] = field.Type.String()
+	}
+
+	other := map[string]interface{}{
+		"Fields":  fields,
+		"Columns": vf.Cols,
+		"Value":   vf.Value,
+	}
+	if vf.Vindex != nil {
+		other["Vindex"] = vf.Vindex.String()
+	}
+
+	return PrimitiveDescription{
+		OperatorType: "VindexFunc",
+		Variant:      vindexOpcodeName[vf.Opcode],
+		Other:        other,
+	}
 }


Test patch:
diff --git a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt
index 5423f80df5..50c7e60b86 100644
--- a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt
@@ -465,7 +465,22 @@
     "OrderBy": "2 ASC",
     "Inputs": [
       {
-        "OperatorType": "vindexfunc - not implemented"
+        "OperatorType": "VindexFunc",
+        "Variant": "VindexMap",
+        "Columns": [
+          0,
+          1,
+          2,
+          3
+        ],
+        "Fields": {
+          "id": "VARBINARY",
+          "keyspace_id": "VARBINARY",
+          "range_end": "VARBINARY",
+          "range_start": "VARBINARY"
+        },
+        "Value": ":id",
+        "Vindex": "user_index"
       }
     ]
   }
diff --git a/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt b/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt
index 58f1bade0d..88356784fd 100644
--- a/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt
@@ -4,7 +4,22 @@
   "QueryType": "SELECT",
   "Original": "select id, keyspace_id, range_start, range_end from user_index where id = :id",
   "Instructions": {
-    "OperatorType": "vindexfunc - not implemented"
+    "OperatorType": "VindexFunc",
+    "Variant": "VindexMap",
+    "Columns": [
+      0,
+      1,
+      2,
+      3
+    ],
+    "Fields": {
+      "id": "VARBINARY",
+      "keyspace_id": "VARBINARY",
+      "range_end": "VARBINARY",
+      "range_start": "VARBINARY"
+    },
+    "Value": ":id",
+    "Vindex": "user_index"
   }
 }
 
@@ -14,7 +29,22 @@
   "QueryType": "SELECT",
   "Original": "select * from user_index where id = :id",
   "Instructions": {
-    "OperatorType": "vindexfunc - not implemented"
+    "OperatorType": "VindexFunc",
+    "Variant": "VindexMap",
+    "Columns": [
+      0,
+      1,
+      2,
+      3
+    ],
+    "Fields": {
+      "id": "VARBINARY",
+      "keyspace_id": "VARBINARY",
+      "range_end": "VARBINARY",
+      "range_start": "VARBINARY"
+    },
+    "Value": ":id",
+    "Vindex": "user_index"
   }
 }
 
@@ -24,7 +54,19 @@
   "QueryType": "SELECT",
   "Original": "select id, keyspace_id, id from user_index where id = :id",
   "Instructions": {
-    "OperatorType": "vindexfunc - not implemented"
+    "OperatorType": "VindexFunc",
+    "Variant": "VindexMap",
+    "Columns": [
+      0,
+      1,
+      0
+    ],
+    "Fields": {
+      "id": "VARBINARY",
+      "keyspace_id": "VARBINARY"
+    },
+    "Value": ":id",
+    "Vindex": "user_index"
   }
 }
 
@@ -38,7 +80,19 @@
   "QueryType": "SELECT",
   "Original": "select id, keyspace_id, id from second_user.hash_dup where id = :id",
   "Instructions": {
-    "OperatorType": "vindexfunc - not implemented"
+    "OperatorType": "VindexFunc",
+    "Variant": "VindexMap",
+    "Columns": [
+      0,
+      1,
+      0
+    ],
+    "Fields": {
+      "id": "VARBINARY",
+      "keyspace_id": "VARBINARY"
+    },
+    "Value": ":id",
+    "Vindex": "hash_dup"
   }
 }
 
@@ -54,7 +108,16 @@
     "TableName": "_unsharded",
     "Inputs": [
       {
-        "OperatorType": "vindexfunc - not implemented"
+        "OperatorType": "VindexFunc",
+        "Variant": "VindexMap",
+        "Columns": [
+          1
+        ],
+        "Fields": {
+          "keyspace_id": "VARBINARY"
+        },
+        "Value": ":id",
+        "Vindex": "user_index"
       },
       {
         "OperatorType": "Route",
@@ -94,7 +157,16 @@
         "Table": "unsharded"
       },
       {
-        "OperatorType": "vindexfunc - not implemented"
+        "OperatorType": "VindexFunc",
+        "Variant": "VindexMap",
+        "Columns": [
+          1
+        ],
+        "Fields": {
+          "keyspace_id": "VARBINARY"
+        },
+        "Value": ":id",
+        "Vindex": "user_index"
       }
     ]
   }
@@ -112,7 +184,18 @@
     "TableName": "_unsharded",
     "Inputs": [
       {
-        "OperatorType": "vindexfunc - not implemented"
+        "OperatorType": "VindexFunc",
+        "Variant": "VindexMap",
+        "Columns": [
+          0,
+          1
+        ],
+        "Fields": {
+          "id": "VARBINARY",
+          "keyspace_id": "VARBINARY"
+        },
+        "Value": ":id",
+        "Vindex": "user_index"
       },
       {
         "OperatorType": "Route",
@@ -141,7 +224,18 @@
     "TableName": "_unsharded",
     "Inputs": [
       {
-        "OperatorType": "vindexfunc - not implemented"
+        "OperatorType": "VindexFunc",
+        "Variant": "VindexMap",
+        "Columns": [
+          1,
+          0
+        ],
+        "Fields": {
+          "id": "VARBINARY",
+          "keyspace_id": "VARBINARY"
+        },
+        "Value": ":id",
+        "Vindex": "user_index"
       },
       {
         "OperatorType": "Route",
@@ -170,7 +264,18 @@
     "TableName": "_unsharded",
     "Inputs": [
       {
-        "OperatorType": "vindexfunc - not implemented"
+        "OperatorType": "VindexFunc",
+        "Variant": "VindexMap",
+        "Columns": [
+          1,
+          0
+        ],
+        "Fields": {
+          "id": "VARBINARY",
+          "keyspace_id": "VARBINARY"
+        },
+        "Value": ":id",
+        "Vindex": "user_index"
       },
       {
         "OperatorType": "Route",