浏览代码

session: use proto 4 pkey columns

Protocol v4 returns the primary key columns for a query on prepare,
so we dont need parse the partition key.
Chris Bannister 9 年之前
父节点
当前提交
1fff315ad5
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20 0
      session.go

+ 20 - 0
session.go

@@ -403,6 +403,22 @@ func (s *Session) routingKeyInfo(stmt string) (*routingKeyInfo, error) {
 		return nil, nil
 	}
 
+	if len(info.request.pkeyColumns) > 0 {
+		// proto v4 dont need to calculate primary key columns
+		types := make([]TypeInfo, len(info.request.pkeyColumns))
+		for i, col := range info.request.pkeyColumns {
+			types[i] = info.request.columns[col].TypeInfo
+		}
+
+		routingKeyInfo := &routingKeyInfo{
+			indexes: info.request.pkeyColumns,
+			types:   types,
+		}
+
+		inflight.value = routingKeyInfo
+		return routingKeyInfo, nil
+	}
+
 	// get the table metadata
 	table := info.request.columns[0].Table
 
@@ -1154,6 +1170,10 @@ type routingKeyInfo struct {
 	types   []TypeInfo
 }
 
+func (r *routingKeyInfo) String() string {
+	return fmt.Sprintf("routing key index=%v types=%v", r.indexes, r.types)
+}
+
 func (r *routingKeyInfoLRU) Remove(key string) {
 	r.mu.Lock()
 	r.lru.Remove(key)