Giter VIP home page Giter VIP logo

Comments (3)

mfussenegger avatar mfussenegger commented on September 24, 2024 1

That's a bigger topic then as subqueries are generally treated in a special way, independent of the evaluation logic of an expression.

from crate.

mfussenegger avatar mfussenegger commented on September 24, 2024

Only evaluate "the arguments that are needed to determine the result" as in

This is actually kinda the case, except that we also have a constant-folding/normalization step to reduce operations like 1 + 1 to 2, to avoid having to repeat the step per row.

In your example the sleep parameter is literal, so this logic kicks in.

How does the expensive lookup in your actual use-case look like?

from crate.

hlcianfagna avatar hlcianfagna commented on September 24, 2024

How does the expensive lookup in your actual use-case look like?

It is along the lines of something like this:

CREATE TABLE invoices (
	some_data TEXT
	,customer_id INT
	,invoice_specific_payment_terms TEXT
);

INSERT INTO invoices
SELECT 'abc',1,'60 days from receipt of invoice';

REFRESH TABLE invoices;

--> NB in this example invoice_specific_payment_terms is never NULL

CREATE TABLE customers (
	customer_id INT
	,customer_default_payment_terms TEXT
);

INSERT INTO customers
SELECT 1,'30 days from receipt of invoice';

REFRESH TABLE customers;

CREATE TABLE distributed_summits AS
SELECT * FROM sys.summits;

ANALYZE;

SELECT some_data,
	CASE
		WHEN invoice_specific_payment_terms IS NOT NULL
			THEN invoice_specific_payment_terms
		ELSE (	SELECT customer_default_payment_terms
				FROM customers
				CROSS JOIN distributed_summits s1				
				CROSS JOIN distributed_summits s2
				CROSS JOIN distributed_summits s3
				WHERE customers.customer_id=invoices.customer_id
				ORDER BY s3.height DESC
				LIMIT 1
			)
	END 
FROM invoices;

from crate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.