提交 ccbbfa38 编写于 作者: V Vlad Ilyushchenko

GRIFFIN: refactored insert further to inline CairoEngine

上级 2c2481ff
......@@ -23,7 +23,6 @@
package io.questdb.cairo.sql;
import io.questdb.cairo.CairoEngine;
import io.questdb.griffin.SqlExecutionContext;
public interface InsertStatement {
......@@ -31,5 +30,5 @@ public interface InsertStatement {
long getStructureVersion();
InsertMethod createMethod(CairoEngine engine, SqlExecutionContext executionContext);
InsertMethod createMethod(SqlExecutionContext executionContext);
}
......@@ -37,16 +37,19 @@ public class InsertStatementImpl implements InsertStatement {
private final long structureVersion;
private final String tableName;
private final InsertMethodImpl insertMethod = new InsertMethodImpl();
private final CairoEngine engine;
private SqlExecutionContext lastUsedContext;
// todo: recycle these
public InsertStatementImpl(
CairoEngine engine,
String tableName,
VirtualRecord virtualRecord,
SqlCompiler.RecordToRowCopier copier,
Function timestampFunction,
long structureVersion
) {
this.engine = engine;
this.tableName = tableName;
this.virtualRecord = virtualRecord;
this.copier = copier;
......@@ -89,7 +92,7 @@ public class InsertStatementImpl implements InsertStatement {
}
@Override
public InsertMethod createMethod(CairoEngine engine, SqlExecutionContext executionContext) {
public InsertMethod createMethod(SqlExecutionContext executionContext) {
if (lastUsedContext != executionContext) {
initContext(executionContext);
}
......
......@@ -1183,7 +1183,7 @@ public class SqlCompiler implements Closeable {
VirtualRecord record = new VirtualRecord(valueFunctions);
RecordToRowCopier copier = assembleRecordToRowCopier(asm, record, metadata, columnFilter);
return compiledQuery.ofInsert(new InsertStatementImpl(Chars.toString(name.token), record, copier, timestampFunction, structureVersion));
return compiledQuery.ofInsert(new InsertStatementImpl(engine, Chars.toString(name.token), record, copier, timestampFunction, structureVersion));
} catch (SqlException e) {
Misc.freeObjList(valueFunctions);
throw e;
......
......@@ -115,7 +115,7 @@ public class InsertTest extends AbstractGriffinTest {
compiler.compile("alter table balances drop column ccy");
insertStatement.createMethod(engine, sqlExecutionContext);
insertStatement.createMethod(sqlExecutionContext);
} catch (WriterOutOfDateException ignored) {
}
......@@ -135,7 +135,7 @@ public class InsertTest extends AbstractGriffinTest {
Assert.assertEquals(CompiledQuery.INSERT, cq.getType());
InsertStatement insertStatement = cq.getInsertStatement();
try (InsertMethod method = insertStatement.createMethod(engine, sqlExecutionContext)) {
try (InsertMethod method = insertStatement.createMethod(sqlExecutionContext)) {
method.execute();
method.commit();
}
......@@ -145,11 +145,12 @@ public class InsertTest extends AbstractGriffinTest {
bindVariableService.setDouble("bal", 56.4);
try (InsertMethod method = insertStatement.createMethod(engine, sqlExecutionContext)) {
try (InsertMethod method = insertStatement.createMethod(sqlExecutionContext)) {
method.execute();
method.commit();
}
sink.clear();
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), insertStatement.getTableName())) {
printer.print(reader.getCursor(), reader.getMetadata(), true);
}
......@@ -175,7 +176,7 @@ public class InsertTest extends AbstractGriffinTest {
CompiledQuery cq = compiler.compile("insert into balances values (1, 'USD', 356.12)");
Assert.assertEquals(CompiledQuery.INSERT, cq.getType());
InsertStatement insert = cq.getInsertStatement();
try (InsertMethod method = insert.createMethod(engine, sqlExecutionContext)) {
try (InsertMethod method = insert.createMethod(sqlExecutionContext)) {
method.execute();
method.commit();
}
......@@ -183,6 +184,7 @@ public class InsertTest extends AbstractGriffinTest {
String expected = "cust_id\tccy\tbalance\n" +
"1\tUSD\t356.120000000000\n";
sink.clear();
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), insert.getTableName())) {
printer.print(reader.getCursor(), reader.getMetadata(), true);
TestUtils.assertEquals(expected, sink);
......@@ -258,7 +260,7 @@ public class InsertTest extends AbstractGriffinTest {
Assert.assertEquals(CompiledQuery.INSERT, cq.getType());
InsertStatement insert = cq.getInsertStatement();
try (InsertMethod method = insert.createMethod(engine, sqlExecutionContext)) {
try (InsertMethod method = insert.createMethod(sqlExecutionContext)) {
// Assert.assertEquals(writer.getStructureVersion(), insert.getStructureVersion());
for (int i = 0; i < 1_000_000; i++) {
bindVariableService.setInt(0, rnd.nextInt());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册