Luo Chen has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/2532
Change subject: [ASTERIXDB-2334] Fix Range Predicate for Composite Key Search
......................................................................
[ASTERIXDB-2334] Fix Range Predicate for Composite Key Search
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Currently during a primary btree search, we always use the range limit
of the first search key. However, this is incorrect for prefix range
search. This patch fixes this bug by using the correct range limit
during index search.
Change-Id: Ie2c432c78043913a9dcf9b8a2eb31db8c548d8d2
---
M
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.1.ddl.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.2.update.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.3.query.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.1.ddl.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.2.update.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-920.3.query.sqlpp
M
asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-low-high/composite-low-high.1.adm
A
asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-prefix/composite-prefix.1.adm
A
asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.1.adm
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
11 files changed, 209 insertions(+), 8 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/32/2532/1
diff --git
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
index a82e780..60d4d3d 100644
---
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
+++
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
@@ -528,11 +528,6 @@
}
}
- if (primaryIndexPostProccessingIsNeeded) {
- Arrays.fill(lowKeyInclusive, true);
- Arrays.fill(highKeyInclusive, true);
- }
-
// determine cases when prefix search could be applied
for (int i = 1; i < lowKeyExprs.length; i++) {
if (lowKeyLimits[0] == null && lowKeyLimits[i] != null ||
lowKeyLimits[0] != null && lowKeyLimits[i] == null
@@ -542,6 +537,12 @@
primaryIndexPostProccessingIsNeeded = true;
}
}
+
+ if (primaryIndexPostProccessingIsNeeded) {
+ Arrays.fill(lowKeyInclusive, true);
+ Arrays.fill(highKeyInclusive, true);
+ }
+
if (lowKeyLimits[0] == null) {
lowKeyInclusive[0] = true;
}
@@ -563,8 +564,10 @@
BTreeJobGenParams jobGenParams = new
BTreeJobGenParams(chosenIndex.getIndexName(), IndexType.BTREE,
dataset.getDataverseName(), dataset.getDatasetName(),
retainInput, requiresBroadcast);
- jobGenParams.setLowKeyInclusive(lowKeyInclusive[0]);
- jobGenParams.setHighKeyInclusive(highKeyInclusive[0]);
+ jobGenParams
+
.setLowKeyInclusive(lowKeyInclusive[primaryIndexPostProccessingIsNeeded ? 0 :
numSecondaryKeys - 1]);
+ jobGenParams
+
.setHighKeyInclusive(highKeyInclusive[primaryIndexPostProccessingIsNeeded ? 0 :
numSecondaryKeys - 1]);
jobGenParams.setIsEqCondition(isEqCondition);
jobGenParams.setLowKeyVarList(keyVarList, 0, numLowKeys);
jobGenParams.setHighKeyVarList(keyVarList, numLowKeys, numHighKeys);
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.1.ddl.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.1.ddl.sqlpp
new file mode 100644
index 0000000..ad1c308
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.1.ddl.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description : This test case is to verify composite key prefix search
+ * Expected Res : Success
+ * Date : 23 March 2018
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type PointType as closed {
+x:int,
+y:int
+};
+
+create dataset Points(PointType) primary key x, y;
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.2.update.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.2.update.sqlpp
new file mode 100644
index 0000000..122b5a8
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.2.update.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+insert into Points {"x": 1, "y": 1};
+insert into Points {"x": 2, "y": 1};
+insert into Points {"x": 2, "y": 2};
+insert into Points {"x": 2, "y": 3};
+insert into Points {"x": 2, "y": 4};
+insert into Points {"x": 2, "y": 5};
+insert into Points {"x": 3, "y": 1};
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.3.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.3.query.sqlpp
new file mode 100644
index 0000000..c37d492
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/composite-prefix/composite-prefix.3.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+use test;
+
+select value p
+from Points p
+where p.x=2
+and p.y>=2 and p.y<4
+order by p.x,p.y;
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.1.ddl.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.1.ddl.sqlpp
new file mode 100644
index 0000000..0e7bad9
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.1.ddl.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description : This test case is to verify the fix for ASTERIXDB-2334
+ : https://issues.apache.org/jira/browse/ASTERIXDB-2334
+ * Expected Res : Success
+ * Date : 23 March 2018
+ */
+
+DROP DATAVERSE earthquake IF EXISTS;
+CREATE DATAVERSE earthquake;
+USE earthquake;
+
+CREATE TYPE QzExternalTypeNew AS {
+stationid: string,
+pointid: string,
+itemid: string,
+samplerate: string,
+startdate: string,
+obsvalue: string
+};
+
+CREATE DATASET qz9130all(QzExternalTypeNew) PRIMARY KEY
stationid,pointid,itemid,samplerate,startdate;
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.2.update.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.2.update.sqlpp
new file mode 100644
index 0000000..e2d6046
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.2.update.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use earthquake;
+
+INSERT INTO qz9130all(
{"stationid":"01","pointid":"5","itemid":"9130","samplerate":"01","startdate":"20080509","obsvalue":"9"}
);
+INSERT INTO qz9130all(
{"stationid":"01","pointid":"5","itemid":"9130","samplerate":"01","startdate":"20080510","obsvalue":"9"}
);
+INSERT INTO qz9130all(
{"stationid":"01","pointid":"5","itemid":"9130","samplerate":"01","startdate":"20080511","obsvalue":"9"}
);
+INSERT INTO qz9130all(
{"stationid":"01","pointid":"5","itemid":"9130","samplerate":"01","startdate":"20080512","obsvalue":"9"}
);
+INSERT INTO qz9130all(
{"stationid":"01","pointid":"5","itemid":"9130","samplerate":"01","startdate":"20080513","obsvalue":"9"}
);
+INSERT INTO qz9130all(
{"stationid":"01","pointid":"5","itemid":"9130","samplerate":"01","startdate":"20080514","obsvalue":"9"}
);
+INSERT INTO qz9130all(
{"stationid":"01","pointid":"5","itemid":"9130","samplerate":"01","startdate":"20080515","obsvalue":"9"}
);
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-920.3.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-920.3.query.sqlpp
new file mode 100644
index 0000000..622937e
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-920.3.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+use earthquake;
+
+SELECT startdate
+FROM qz9130all
+WHERE samplerate='01' and stationid='01' and pointid='5' and itemid='9130' and
startdate >= '20080510' and startdate < '20080513'
+ORDER BY startdate;
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-low-high/composite-low-high.1.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-low-high/composite-low-high.1.adm
index 8c4166d..625f0fd 100644
---
a/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-low-high/composite-low-high.1.adm
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-low-high/composite-low-high.1.adm
@@ -1,3 +1,3 @@
{ "x": 15, "y": 40 }
{ "x": 20, "y": 50 }
-{ "x": 60, "y": 40 }
\ No newline at end of file
+{ "x": 60, "y": 40 }
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-prefix/composite-prefix.1.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-prefix/composite-prefix.1.adm
new file mode 100644
index 0000000..dbf0ba7
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/composite-prefix/composite-prefix.1.adm
@@ -0,0 +1,2 @@
+{ "x": 2, "y": 2 }
+{ "x": 2, "y": 3 }
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.1.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.1.adm
new file mode 100644
index 0000000..41da74e
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/results/composite-key/query-ASTERIXDB-2334/query-ASTERIXDB-2334.1.adm
@@ -0,0 +1,3 @@
+{ "startdate": "20080510" }
+{ "startdate": "20080511" }
+{ "startdate": "20080512" }
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 0967ba6..832bb06 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -9743,10 +9743,20 @@
<output-dir compare="Text">query-ASTERIXDB-920</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="composite-key">
+ <compilation-unit name="query-ASTERIXDB-2334">
+ <output-dir compare="Text">query-ASTERIXDB-2334</output-dir>
+ </compilation-unit>
+ </test-case>
<test-case FilePath="composite-key">
<compilation-unit name="composite-low-high">
<output-dir compare="Text">composite-low-high</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="composite-key">
+ <compilation-unit name="composite-prefix">
+ <output-dir compare="Text">composite-prefix</output-dir>
+ </compilation-unit>
+ </test-case>
</test-group>
</test-suite>
--
To view, visit https://asterix-gerrit.ics.uci.edu/2532
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie2c432c78043913a9dcf9b8a2eb31db8c548d8d2
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: release-0.9.4-pre-rc
Gerrit-Owner: Luo Chen <[email protected]>