Skip to main content

Query

Struct Query 

Source
pub struct Query<'a> { /* private fields */ }
Expand description

A plan that has been built and is ready to run.

It borrows the plan and the catalog it was built from, which is what 'a is. A scan reads its rows out of the catalog’s table rather than copying them and an expression reads its constants out of the plan’s arena, so a query cannot outlive either.

Implementations§

Source§

impl<'a> Query<'a>

Source

pub fn schema(&self) -> &Schema

The columns this query produces.

Source

pub fn pipelines(&self) -> usize

How many pipelines the query runs.

Source

pub fn run(&self, cancel: &Cancel, pool: &Pool) -> Result<()>

Runs every pipeline, stopping at the first one that fails.

Each one is timed against its own driver, which is the loop that runs a pipeline rather than any operator in it. That time is not nothing: on a scan of ten million rows the loop goes round ten thousand times, and none of it sits inside an operator’s own span, so without a driver it is time the metrics document cannot account for.

The lease is taken per pipeline and given back at the end of it, so a query whose scan uses nine threads and whose sort uses one holds nine for as long as the scan and one after that, and the threads it is not using are there for whatever else the database is running.

§Errors

Whatever any operator reports, or ErrorCode::Interrupt if the token says to stop. The check is per chunk, in the driver, which is why no operator here holds a token of its own except the join, whose nested loop can outlive a chunk.

Source

pub fn worker_cpu_ns(&self) -> u64

CPU nanoseconds this query burned on threads other than the one that ran it.

A caller timing the execution reads its own thread’s CPU clock, which is the only clock there is that attributes work to the thread that did it, and which therefore cannot see the workers. This is what it missed.

Source

pub fn widest(&self) -> usize

The most instances any one pipeline of this query ran as.

Not the setting and not an average. A query whose scan ran on nine threads and whose sort ran on one reports nine, because the question this answers is what the query was able to use.

Source

pub fn next_chunk(&self) -> Result<Option<Chunk>>

The next chunk of the answer, or None when there are no more.

Only meaningful after Query::run has returned. The serial driver runs a pipeline to completion, so everything the query produced is queued by then, and taking a chunk here removes it from the queue rather than copying it out.

§Errors

ErrorCode::Internal if a thread panicked while holding the queue.

Source

pub fn collect(&self, cancel: &Cancel, pool: &Pool) -> Result<Vec<Chunk>>

Runs the query and collects everything it produced.

The convenience the tests and the simple callers want. A caller that cares about holding one chunk at a time calls Query::run and Query::next_chunk itself.

§Errors

The same as Query::run.

Trait Implementations§

Source§

impl<'a> Debug for Query<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Query<'a>

§

impl<'a> !RefUnwindSafe for Query<'a>

§

impl<'a> !UnwindSafe for Query<'a>

§

impl<'a> Send for Query<'a>

§

impl<'a> Sync for Query<'a>

§

impl<'a> Unpin for Query<'a>

§

impl<'a> UnsafeUnpin for Query<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.