Exists is modeled as:
<pre>
- Project($0 > 0)
- Aggregation(COUNT(*))
- Limit(1)
-- subquery
</pre>
181125
private PlanBuilder appendExistSubqueryApplyNode(PlanBuilder subPlan, ExistsPredicate existsPredicate, boolean correlationAllowed)
    {
        if (subPlan.canTranslate(existsPredicate)) {
            // given subquery is already appended
            return subPlan;
        }

        PlanBuilder subqueryPlan = createPlanBuilder(existsPredicate.getSubquery());

        PlanNode subqueryPlanRoot = subqueryPlan.getRoot();
        if (isAggregationWithEmptyGroupBy(subqueryPlanRoot)) {
            subPlan.getTranslations().put(existsPredicate, BooleanLiteral.TRUE_LITERAL);
            return subPlan;
        }

        // add an explicit projection that removes all columns
        PlanNode subqueryNode = new ProjectNode(idAllocator.getNextId(), subqueryPlan.getRoot(), Assignments.of());

        Symbol exists = symbolAllocator.newSymbol("exists", BOOLEAN);
        subPlan.getTranslations().put(existsPredicate, exists);
        ExistsPredicate rewrittenExistsPredicate = new ExistsPredicate(BooleanLiteral.TRUE_LITERAL);
        return appendApplyNode(
                subPlan,
                existsPredicate.getSubquery(),
                subqueryNode,
                Assignments.of(exists, rewrittenExistsPredicate),
                correlationAllowed);
    }
357366
def column_exists(self, tablename: str, column: str) -> bool:
        """"""
        sql = """
            SELECT COUNT(*)
            FROM information_schema.columns
            WHERE table_name=?
            AND column_name=?
            AND table_schema={}
        """.format(self.get_current_schema_expr())
        row = self.fetchone(sql, tablename, column)
        return True if row[0] >= 1 else False
1135401
final public boolean exists() {
		final Model m = Query.one(
				getClass(),
				String.format("SELECT * FROM %s WHERE %s LIMIT 1",
						Utils.getTableName(getClass()),
						Utils.getWhereStatement(this))).get();
		return m != null;
	}
474219
def exists(self, primary_key):
        
        '''
            
        '''
        
        select_statement = self.table.select(self.table).where(self.table.c.id==primary_key)
        record_object = self.session.execute(select_statement).first()
        if record_object:
            return True
        return False
45049
def exists(self, index, doc_type, id, **query_params):
        
        path = make_path(index, doc_type, id)
        return self._send_request('HEAD', path, params=query_params)
1192097
@SafeVarargs
    public final boolean exists(final String query, final Object... parameters) {
        final QueryResult resultSet = execute(query, parameters);

        return resultSet.iterator().hasNext();
    }
350608
@SafeVarargs
    public final boolean exists(String sql, Object... parameters) {
        final Cursor cursor = rawQuery(sql, parameters);

        try {
            return cursor.moveToNext();
        } finally {
            cursor.close();
        }
    }
297229
def exists(self):
        
        limit = self.limit_

        result = self.limit(1).count() > 0

        self.limit(limit)

        return result
1340961
@Override
	public boolean exists() {
		// Return false if any of the resources in this aggregated resource
		// does not exist
		boolean result = true;
		for (IResource resource : resources) {
			if (!resource.exists()) {
				result = false;
				break;
			}
		}
		return result;
	}
747646
def _get(self, operation, field):
        """"""
        self._check_exists()
        query = {Mark.FLD_OP: operation.name,
                 Mark.FLD_MARK + "." + field: {"$exists": True}}
        return self._track.find_one(query)
1322938
private PExp getImpliesExists(AMapCompMapExp exp, ILexNameToken finmap,
			ILexNameToken findex)
	{
		AExistsExp exists = new AExistsExp();
		exists.setBindList(getSetBindList(finmap, findex));
		exists.setPredicate(getExistsPredicate(exp, finmap, findex));
		return exists;
	}
578012
def count(self, *_clauses, **kwargs):
        """"""
        # NOTE: this does not have support for limit and offset since I can't
        # see how this is useful. Still, there might be compatibility issues
        # with people using these flags. Let's see how it goes.
        if not self.exists:
            return 0

        args = self._args_to_clause(kwargs, clauses=_clauses)
        query = select([func.count()], whereclause=args)
        query = query.select_from(self.table)
        rp = self.db.executable.execute(query)
        return rp.fetchone()[0]
1009696
protected AbstractExpression simplifyExistsSubqueryStmt(
            AbstractExpression originalExistExpr) {
        // Verify the edge case of EXISTS ( table-agg-without-having-groupby)
        // for which the correct handling is to optimize out the exists
        // clause entirely as trivially true or false
        // if limit = 0 or offset > 0
        if (m_limitOffset.getLimit() == 0) {
            return ConstantValueExpression.getFalse();
        }

        // Except for "limit 0 offset ?" which is already covered,
        // can't optimize away the entire expression if there are
        // limit and/or offset parameters
        if (m_having == null &&
                m_groupByColumns.isEmpty() &&
                ! hasLimitOrOffsetParameters() &&
                displaysAgg()) {
            if (m_limitOffset.getOffset() == 0) {
                return ConstantValueExpression.getTrue();
            }
            else {
                return ConstantValueExpression.getFalse();
            }
        }

        // Remove ORDER BY columns
        m_orderColumns.clear();

        // Redo TVE placement since we've cleared the ORDER BY columns.
        placeTVEsinColumns();

        // Drop DISTINCT expression
        m_distinct = false;

        // Set LIMIT 1
        if (m_limitOffset.getLimitParameterId() == -1) {
            m_limitOffset.setLimit(1);
        }

        prepareLimitPlanNode(this, m_limitOffset);

        return originalExistExpr;
    }
620087
public static Long count(String query, Object... params) {
        return ModelDelegate.count(modelClass(), query, params);
    }
938929
def exists(self, model_class, ID):
        ''''''

        assert hasattr(model_class, '_fields'), 'Not a valid model class'
        res = self.get(model_class, id=ID, fetchOne=True)
        if res:
            return True
        return False
1204261
func (q *Query) Exists(model interface{}) (bool, error) {
	tmpQuery := Q(q.Connection)
	q.Clone(tmpQuery) //avoid meddling with original query

	var res bool

	err := tmpQuery.Connection.timeFunc("Exists", func() error {
		tmpQuery.Paginator = nil
		tmpQuery.orderClauses = clauses{}
		tmpQuery.limitResults = 0
		query, args := tmpQuery.ToSQL(&Model{Value: model})

		// when query contains custom selected fields / executed using RawQuery,
		// sql may already contains limit and offset
		if rLimitOffset.MatchString(query) {
			foundLimit := rLimitOffset.FindString(query)
			query = query[0 : len(query)-len(foundLimit)]
		} else if rLimit.MatchString(query) {
			foundLimit := rLimit.FindString(query)
			query = query[0 : len(query)-len(foundLimit)]
		}

		existsQuery := fmt.Sprintf("SELECT EXISTS (%s)", query)
		log(logging.SQL, existsQuery, args...)
		return q.Connection.Store.Get(&res, existsQuery, args...)
	})
	return res, err
}
40281
def view_exists?(query)
      if query.nil?
        raise ArgumentError, 'Query cannot be nil'
      end

      result = query(query)

      !result.empty?
    end