Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](planner)VecNotImplException thrown when query need rewrite and some slot cannot changed to nullable #9589

Merged
merged 3 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,6 @@ private static class GlobalState {

private final long autoBroadcastJoinThreshold;

/**
* This property is mainly used to store the vectorized switch of the current query.
* true: the vectorization of the current query is turned on
* false: the vectorization of the current query is turned off.
* It is different from the vectorized switch`enableVectorizedEngine` of the session.
* It is only valid for a single query, while the session switch is valid for all queries in the session.
* It cannot be set directly by the user, only by inheritance from session`enableVectorizedEngine`
* or internal adjustment of the system.
*/
private boolean enableQueryVec;

public GlobalState(Catalog catalog, ConnectContext context) {
this.catalog = catalog;
this.context = context;
Expand Down Expand Up @@ -361,9 +350,6 @@ public GlobalState(Catalog catalog, ConnectContext context) {
// autoBroadcastJoinThreshold is a "final" field, must set an initial value for it
autoBroadcastJoinThreshold = 0;
}
if (context != null) {
enableQueryVec = context.getSessionVariable().enableVectorizedEngine();
}
}
}

Expand Down Expand Up @@ -668,27 +654,6 @@ public ExprRewriter getMVExprRewriter() {
return globalState.mvExprRewriter;
}

/**
* Only the top-level `query vec` value of the query analyzer represents the value of the entire query.
* Other sub-analyzers cannot represent the value of `query vec`.
* @return
*/
public boolean enableQueryVec() {
if (ancestors.isEmpty()) {
return globalState.enableQueryVec;
} else {
return ancestors.get(ancestors.size() - 1).enableQueryVec();
}
}

/**
* Since analyzer cannot get sub-analyzers from top to bottom.
* So I can only set the `query vec` variable of the top level analyzer of query to true.
*/
public void disableQueryVec() {
globalState.enableQueryVec = false;
}

/**
* Return descriptor of registered table/alias.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package org.apache.doris.common.util;

import org.apache.doris.analysis.Analyzer;
import org.apache.doris.analysis.SetVar;
import org.apache.doris.analysis.StringLiteral;
import org.apache.doris.common.DdlException;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.StmtExecutor;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.qe.VariableMgr;

public class VectorizedUtil {
/**
Expand All @@ -33,15 +36,7 @@ public static boolean isVectorized() {
if (connectContext == null) {
return false;
}
StmtExecutor stmtExecutor = connectContext.getExecutor();
if (stmtExecutor == null) {
return connectContext.getSessionVariable().enableVectorizedEngine();
}
Analyzer analyzer = stmtExecutor.getAnalyzer();
if (analyzer == null) {
return connectContext.getSessionVariable().enableVectorizedEngine();
}
return analyzer.enableQueryVec();
return connectContext.getSessionVariable().enableVectorizedEngine();
}

/**
Expand All @@ -63,10 +58,14 @@ public static void switchToQueryNonVec() {
if (connectContext == null) {
return;
}
Analyzer analyzer = connectContext.getExecutor().getAnalyzer();
if (analyzer == null) {
return;
SessionVariable sessionVariable = connectContext.getSessionVariable();
sessionVariable.setIsSingleSetVar(true);
morrySnow marked this conversation as resolved.
Show resolved Hide resolved
try {
VariableMgr.setVar(sessionVariable, new SetVar(
"enable_vectorized_engine",
new StringLiteral("false")));
} catch (DdlException e) {
// do nothing
}
analyzer.disableQueryVec();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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.

package org.apache.doris.analysis;

import org.apache.doris.qe.QueryState.MysqlStateType;
import org.apache.doris.qe.StmtExecutor;
import org.apache.doris.utframe.TestWithFeService;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ReanalyzeTest extends TestWithFeService {
@Override
protected void runBeforeAll() throws Exception {
createDatabase("test");
createTable("create table test.tbl1\n" + "(k1 int, k2 int, v1 int)\n" + "distributed by hash(k1)\n"
+ "properties(\"replication_num\" = \"1\");");
}

@Test
public void testTurnoffVectorizedEngineWhenCannotChangeSlotToNullable() throws Exception {
String sql = "explain select * from test.tbl1 t1"
+ " where (select count(*) from test.tbl1 t2 where t1.k1 = t2.k1) > 0";
connectContext.getSessionVariable().enableVectorizedEngine = true;
StmtExecutor stmtExecutor = new StmtExecutor(connectContext, sql);
connectContext.setExecutor(stmtExecutor);
stmtExecutor.execute();
connectContext.setExecutor(null);
Assertions.assertEquals(MysqlStateType.EOF, connectContext.getState().getStateType());
Assertions.assertTrue(connectContext.getSessionVariable().enableVectorizedEngine());
}
}