From c3bcde9eda77e6e5329f52186a699d436a22d4e7 Mon Sep 17 00:00:00 2001 From: markoszah <74737089+markoszah@users.noreply.github.com> Date: Thu, 13 Feb 2025 10:40:01 +0200 Subject: [PATCH] reverted VirtualScan simplification and added join-related info to VirtualScan --- .../driver/ops/serde/nson/NsonProtocol.java | 4 + .../ops/serde/nson/NsonSerializerFactory.java | 60 +++++-- .../nosql/driver/query/VirtualScan.java | 165 +++++++++++++----- 3 files changed, 174 insertions(+), 55 deletions(-) diff --git a/driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonProtocol.java b/driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonProtocol.java index bd221dfb..e68fc0ee 100644 --- a/driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonProtocol.java +++ b/driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonProtocol.java @@ -108,6 +108,8 @@ public class NsonProtocol { public static String VIRTUAL_SCANS = "vssa"; public static String VIRTUAL_SCAN_SID = "vssid"; public static String VIRTUAL_SCAN_PID = "vspid"; + public static String VIRTUAL_SCAN_NUM_TABLES = "vsnt"; + public static String VIRTUAL_SCAN_CURRENT_INDEX_RANGE = "vscir"; public static String VIRTUAL_SCAN_PRIM_KEY = "vspk"; public static String VIRTUAL_SCAN_SEC_KEY = "vssk"; public static String VIRTUAL_SCAN_MOVE_AFTER = "vsma"; @@ -276,6 +278,8 @@ public class NsonProtocol { {VIRTUAL_SCANS,"VIRTUAL_SCANS"}, {VIRTUAL_SCAN_SID,"VIRTUAL_SCAN_SID"}, {VIRTUAL_SCAN_PID,"VIRTUAL_SCAN_PID"}, + {VIRTUAL_SCAN_NUM_TABLES,"VIRTUAL_SCAN_NUM_TABLES"}, + {VIRTUAL_SCAN_CURRENT_INDEX_RANGE,"VIRTUAL_SCAN_CURRENT_INDEX_RANGE"}, {VIRTUAL_SCAN_PRIM_KEY,"VIRTUAL_SCAN_PRIM_KEY"}, {VIRTUAL_SCAN_SEC_KEY,"VIRTUAL_SCAN_SEC_KEY"}, {VIRTUAL_SCAN_MOVE_AFTER,"VIRTUAL_SCAN_MOVE_AFTER"}, diff --git a/driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonSerializerFactory.java b/driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonSerializerFactory.java index 98c833ad..59c7cbdf 100644 --- a/driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonSerializerFactory.java +++ b/driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonSerializerFactory.java @@ -101,6 +101,7 @@ import oracle.nosql.driver.query.QueryDriver; import oracle.nosql.driver.query.TopologyInfo; import oracle.nosql.driver.query.VirtualScan; +import oracle.nosql.driver.query.VirtualScan.TableResumeInfo; import oracle.nosql.driver.util.BinaryProtocol.OpCode; import oracle.nosql.driver.util.ByteInputStream; import oracle.nosql.driver.util.ByteOutputStream; @@ -906,16 +907,32 @@ private static void writeVirtualScan(NsonSerializer ns, writeMapField(ns, VIRTUAL_SCAN_SID, vs.sid()); writeMapField(ns, VIRTUAL_SCAN_PID, vs.pid()); - if (queryVersion <= QueryDriver.QUERY_V4 && vs.isFirstBatch()) { - writeMapField(ns, VIRTUAL_SCAN_PRIM_KEY, vs.primKey()); - writeMapField(ns, VIRTUAL_SCAN_SEC_KEY, vs.secKey()); - writeMapField(ns, VIRTUAL_SCAN_MOVE_AFTER, vs.moveAfterResumeKey()); - - writeMapField(ns, VIRTUAL_SCAN_JOIN_DESC_RESUME_KEY, vs.descResumeKey()); - writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_TABLES, vs.joinPathTables()); - writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_KEY, vs.joinPathKey()); - writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_SEC_KEY, vs.joinPathSecKey()); - writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_MATCHED, vs.joinPathMatched()); + if (vs.isFirstBatch()) { + int numTables = 1; + if (queryVersion >= QueryDriver.QUERY_V5) { + numTables = vs.numTables(); + writeMapField(ns, VIRTUAL_SCAN_NUM_TABLES, numTables); + } + for (int t = 0; t < numTables; ++t) { + writeMapField(ns, VIRTUAL_SCAN_CURRENT_INDEX_RANGE, + vs.currentIndexRange(t)); + writeMapField(ns, VIRTUAL_SCAN_PRIM_KEY, + vs.primKey(t)); + writeMapField(ns, VIRTUAL_SCAN_SEC_KEY, + vs.secKey(t)); + writeMapField(ns, VIRTUAL_SCAN_MOVE_AFTER, + vs.moveAfterResumeKey(t)); + writeMapField(ns, VIRTUAL_SCAN_JOIN_DESC_RESUME_KEY, + vs.descResumeKey(t)); + writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_TABLES, + vs.joinPathTables(t)); + writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_KEY, + vs.joinPathKey(t)); + writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_SEC_KEY, + vs.joinPathSecKey(t)); + writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_MATCHED, + vs.joinPathMatched(t)); + } } endMap(ns, VIRTUAL_SCAN); @@ -1128,6 +1145,10 @@ private static VirtualScan readVirtualScan(ByteInputStream in) byte[] joinPathKey = null; byte[] joinPathSecKey = null; boolean joinPathMatched = false; + int currentIndexRange = 0; + int numTables = 1; + int currTable = 0; + TableResumeInfo[] tableRIs = new TableResumeInfo[1]; MapWalker walker = getMapWalker(in); @@ -1138,6 +1159,11 @@ private static VirtualScan readVirtualScan(ByteInputStream in) sid = Nson.readNsonInt(in); } else if (name.equals(VIRTUAL_SCAN_PID)) { pid = Nson.readNsonInt(in); + } else if (name.equals(VIRTUAL_SCAN_NUM_TABLES)) { + numTables = Nson.readNsonInt(in); + tableRIs = new TableResumeInfo[numTables]; + } else if (name.equals(VIRTUAL_SCAN_CURRENT_INDEX_RANGE)) { + currentIndexRange = Nson.readNsonInt(in); } else if (name.equals(VIRTUAL_SCAN_PRIM_KEY)) { primKey = Nson.readNsonBinary(in); } else if (name.equals(VIRTUAL_SCAN_SEC_KEY)) { @@ -1154,14 +1180,22 @@ private static VirtualScan readVirtualScan(ByteInputStream in) joinPathSecKey = Nson.readNsonBinary(in); } else if (name.equals(VIRTUAL_SCAN_JOIN_PATH_MATCHED)) { joinPathMatched = Nson.readNsonBoolean(in); + tableRIs[currTable] = new TableResumeInfo(currentIndexRange, + primKey, + secKey, + moveAfter, + descResumeKey, + joinPathTables, + joinPathKey, + joinPathSecKey, + joinPathMatched); + ++currTable; } else { skipUnknownField(walker, name); } } - return new VirtualScan(pid, sid, primKey, secKey, moveAfter, - descResumeKey, joinPathTables, joinPathKey, - joinPathSecKey, joinPathMatched); + return new VirtualScan(pid, sid, tableRIs); } private static void readPhase1Results(byte[] arr, QueryResult result) diff --git a/driver/src/main/java/oracle/nosql/driver/query/VirtualScan.java b/driver/src/main/java/oracle/nosql/driver/query/VirtualScan.java index ed1cb905..98342bcd 100644 --- a/driver/src/main/java/oracle/nosql/driver/query/VirtualScan.java +++ b/driver/src/main/java/oracle/nosql/driver/query/VirtualScan.java @@ -10,43 +10,110 @@ public class VirtualScan { - final private int theSID; + public static class TableResumeInfo { + + final private int theCurrentIndexRange; + final private byte[] thePrimResumeKey; + final private byte[] theSecResumeKey; + final private boolean theMoveAfterResumeKey; + + final private byte[] theDescResumeKey; + final private int[] theJoinPathTables; + final private byte[] theJoinPathKey; + final private byte[] theJoinPathSecKey; + final private boolean theJoinPathMatched; + + public TableResumeInfo( + int currentIndexRange, + byte[] primKey, + byte[] secKey, + boolean moveAfterResumeKey, + byte[] descResumeKey, + int[] joinPathTables, + byte[] joinPathKey, + byte[] joinPathSecKey, + boolean joinPathMatched) { + + theCurrentIndexRange = currentIndexRange; + thePrimResumeKey = primKey; + theSecResumeKey = secKey; + theMoveAfterResumeKey = moveAfterResumeKey; + theDescResumeKey = descResumeKey; + theJoinPathTables = joinPathTables; + theJoinPathKey = joinPathKey; + theJoinPathSecKey = joinPathSecKey; + theJoinPathMatched = joinPathMatched; + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + + sb.append("theCurrentIndexRange = ").append(theCurrentIndexRange); + sb.append("\n"); + + if (thePrimResumeKey != null) { + sb.append("thePrimResumeKey = "); + sb.append(PlanIter.printByteArray(thePrimResumeKey)); + sb.append("\n"); + } + + if (theSecResumeKey != null) { + sb.append("theSecResumeKey = "); + sb.append(PlanIter.printByteArray(theSecResumeKey)); + sb.append("\n"); + } + + sb.append("theMoveAfterResumeKey = ").append(theMoveAfterResumeKey); + sb.append("\n"); + + if (theDescResumeKey != null) { + sb.append("theDescResumeKey = "); + sb.append(PlanIter.printByteArray(theDescResumeKey)); + sb.append("\n"); + } + + if (theJoinPathTables != null) { + sb.append("theJoinPathTables = "); + sb.append(PlanIter.printIntArray(theJoinPathTables)); + sb.append("\n"); + } + + if (theJoinPathKey != null) { + sb.append("theJoinPathKey = "); + sb.append(PlanIter.printByteArray(theJoinPathKey)); + sb.append("\n"); + } + + if (theJoinPathSecKey != null) { + sb.append("theJoinPathSecKey = "); + sb.append(PlanIter.printByteArray(theJoinPathSecKey)); + sb.append("\n"); + } + + sb.append("theJoinPathMatched = ").append(theJoinPathMatched); + sb.append("\n"); + + return sb.toString(); + } + } + final private int theSID; final private int thePID; + final private TableResumeInfo[] theTableRIs; - final private byte[] thePrimResumeKey; - final private byte[] theSecResumeKey; - final private boolean theMoveAfterResumeKey; - - final private byte[] theDescResumeKey; - final private int[] theJoinPathTables; - final private byte[] theJoinPathKey; - final private byte[] theJoinPathSecKey; - final private boolean theJoinPathMatched; boolean theFirstBatch = true; public VirtualScan( int pid, int sid, - byte[] primKey, - byte[] secKey, - boolean moveAfterResumeKey, - byte[] descResumeKey, - int[] joinPathTables, - byte[] joinPathKey, - byte[] joinPathSecKey, - boolean joinPathMatched) { + TableResumeInfo[] tableRIs) { + theSID = sid; thePID = pid; - thePrimResumeKey = primKey; - theSecResumeKey = secKey; - theMoveAfterResumeKey = moveAfterResumeKey; - theDescResumeKey = descResumeKey; - theJoinPathTables = joinPathTables; - theJoinPathKey = joinPathKey; - theJoinPathSecKey = joinPathSecKey; - theJoinPathMatched = joinPathMatched; + theTableRIs = tableRIs; } public int sid() { @@ -57,36 +124,44 @@ public int pid() { return thePID; } - public byte[] secKey() { - return theSecResumeKey; + public int numTables() { + return theTableRIs.length; } - public byte[] primKey() { - return thePrimResumeKey; + public int currentIndexRange(int i) { + return theTableRIs[i].theCurrentIndexRange; } - public boolean moveAfterResumeKey() { - return theMoveAfterResumeKey; + public byte[] secKey(int i) { + return theTableRIs[i].theSecResumeKey; } - public byte[] descResumeKey() { - return theDescResumeKey; + public byte[] primKey(int i) { + return theTableRIs[i].thePrimResumeKey; + } + + public boolean moveAfterResumeKey(int i) { + return theTableRIs[i].theMoveAfterResumeKey; + } + + public byte[] descResumeKey(int i) { + return theTableRIs[i].theDescResumeKey; } - public int[] joinPathTables() { - return theJoinPathTables; + public int[] joinPathTables(int i) { + return theTableRIs[i].theJoinPathTables; } - public byte[] joinPathKey() { - return theJoinPathKey; + public byte[] joinPathKey(int i) { + return theTableRIs[i].theJoinPathKey; } - public byte[] joinPathSecKey() { - return theJoinPathSecKey; + public byte[] joinPathSecKey(int i) { + return theTableRIs[i].theJoinPathSecKey; } - public boolean joinPathMatched() { - return theJoinPathMatched; + public boolean joinPathMatched(int i) { + return theTableRIs[i].theJoinPathMatched; } public boolean isFirstBatch() { @@ -103,6 +178,12 @@ public String toString() { sb.append("theFirstBatch = ").append(theFirstBatch); sb.append("\n"); + + for (int i = 0; i < theTableRIs.length; ++i) { + sb.append("Table RI ").append(i).append(":\n"); + sb.append(theTableRIs[i]); + } + return sb.toString(); } }