Querying and data types FAQ
- When should I use
uint256
versus downcast touint64
?- When you emit a
uint256
to a persistence, it is ingested by Apache Pinot asBIG_DECIMAL
. When you emit auint64
, it's ingested asLONG
. In general, Pinot math functions supportLONG
better thanBIG_DECIMAL
. Often there are work-arounds forBIG_DECIMAL
, e.g., usingsum_precision
instead ofsum
--reach out if you're stuck and we can help. - Given the above, we recommend emitting data as
uint256
only when you need the precision. For balances, precision is crucial. For data like block numbers or timestamps, casting touint64
(i.e.,uint64(block.number)
) in the lambda and emitting asuint64
in the schema might make your life easier if you later want to domax(block_number)
.
- When you emit a
- What should I do about
numeric literal out of range
errors?- This relates to Q1 above. Try a query like
select * from @sim.erc20_balance_changes_block where balance > 69803846217511559491961
and you'll run intonumeric literal out of range
. The simplest fix for this is to just pass the number as a string:select * from @sim.erc20_balance_changes_block where balance > '69803846217511559491961'
. You can also use scientific notation:select * from @sim.erc20_balance_changes_block where balance > 6.9e22
, but this comes with a lack of precision. - Another situation where you might run into this is if you're using Global counter as a cursor for API pagination.
- This relates to Q1 above. Try a query like
- Is it better to use WHERE with a subquery or do an inner join?
- It depends--try both and look at the execution time at the bottom of the query editor! Here are some examples of what we're talking about.
-- DEMO PURPOSES ONLY, TABLES DON'T EXIST SELECT order_id, customer_id, order_total FROM Orders WHERE customer_id IN ( SELECT customer_id FROM Customers WHERE customer_status = 'active' )
-- DEMO PURPOSES ONLY, TABLES DON'T EXIST SELECT o.order_id, o.customer_id, o.order_total FROM Orders o INNER JOIN Customers c ON o.customer_id = c.customer_id WHERE c.customer_status = 'active'
- It depends--try both and look at the execution time at the bottom of the query editor! Here are some examples of what we're talking about.
- Why is my query slow? Can I make it faster?
- It depends... Probably! Hit us on on Telegram--we're happy to help.
Updated 24 days ago