class QDistinct extends QOperator {

    private final Index index;
    private final int[] columnIds;
    private final int size;
    private Cursor cursor;

    QDistinct(Select select) {
        super(select);
        index = select.getTopTableFilter().getIndex();
        columnIds = index.getColumnIds();
        size = columnIds.length;
    }

    @Override
    public void start() {
        cursor = index.findDistinct(session);
        yieldableSelect.disableOlap(); // 无需从oltp转到olap
        tableIterator.setCursor(cursor);
        super.start();
    }

    @Override
    public void run() {<FILL_FUNCTION_BODY>}
}

        while (next()) {
            if (select.isForUpdate && !tryLockRow()) {
                return; // 锁记录失败
            }
            boolean yield = yieldIfNeeded(++loopCount);
            SearchRow found = cursor.getSearchRow();
            Value[] row = new Value[size];
            for (int i = 0; i < size; i++) {
                row[i] = found.getValue(columnIds[i]);
            }
            result.addRow(row);
            rowCount++;
            if (canBreakLoop()) {
                break;
            }
            if (yield)
                return;
        }
        loopEnd = true;
    
<methods>public void <init>(com.lealone.sql.query.Select) ,public boolean canBreakLoop() ,public void copyStatusTo(com.lealone.sql.query.QOperator) ,public com.lealone.sql.expression.evaluator.ExpressionEvaluator createConditionEvaluator(com.lealone.sql.expression.Expression) ,public com.lealone.db.value.Value[] createRow() ,public com.lealone.db.result.LocalResult getLocalResult() ,public boolean isStopped() ,public void onLockedException() ,public void run() ,public void start() ,public void stop() ,public boolean yieldIfNeeded(int) <variables>protected int columnCount,protected final non-sealed com.lealone.sql.expression.evaluator.ExpressionEvaluator conditionEvaluator,protected long limitRows,protected com.lealone.db.result.LocalResult localResult,protected int loopCount,protected boolean loopEnd,protected int maxRows,protected com.lealone.db.result.ResultTarget result,protected int rowCount,protected int sampleSize,protected final non-sealed com.lealone.sql.query.Select select,protected final non-sealed com.lealone.db.session.ServerSession session,protected final non-sealed com.lealone.sql.optimizer.TableIterator tableIterator,protected com.lealone.db.result.ResultTarget target,protected com.lealone.sql.query.YieldableSelect yieldableSelect