Need some help here. I encountered this error on my query: Error: Panic: runtime error: invalid memory address or nil pointer dereference
SELECT
brands AS brand,
departments AS department,
ranks AS `rank`,
ARRAY_SORT( ARRAY_DISTINCT( ARRAY_FLATTEN( category, 1 ) ) ) AS categories,
tags
LET
brands = (
SELECT DISTINCT RAW LOWER(brand)
FROM `bucket`
WHERE `type` = 'product' AND brand IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY LOWER(brand) ASC
),
departments = (
SELECT DISTINCT RAW department
FROM `bucket`
WHERE `type` = 'product' AND department IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY(department) ASC
),
ranks = (
SELECT DISTINCT RAW `rank`.level
FROM `bucket`
WHERE `type` = 'product' AND `rank`.level IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY(`rank`.level) ASC
),
category = (
SELECT DISTINCT RAW categories
FROM `bucket`
WHERE `type` = 'product' AND categories IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
),
tags = (
SELECT DISTINCT RAW tag
FROM `bucket` AS b
UNNEST b.tags AS tag
WHERE b.`type` = 'product' AND b.tags IS NOT MISSING
AND b.status = 'active' AND b.tenant = 'tenant::bucket'
ORDER BY LOWER(tag)
)
Instead of fetching every query you can try the following options and see how it performs.
WITH data AS (SELECT RAW d FROM `bucket` AS d
WHERE `type` = 'product' AND status = 'active' AND tenant = 'tenant::bucket')
SELECT
brands AS brand,
departments AS department,
ranks AS `rank`,
ARRAY_SORT( ARRAY_DISTINCT( ARRAY_FLATTEN( category, 1 ) ) ) AS categories,
tags
LET
brands = (
SELECT DISTINCT RAW LOWER(brand)
FROM data AS d1
WHERE `type` = 'product' AND brand IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY LOWER(brand) ASC
),
departments = (
SELECT DISTINCT RAW department
FROM data AS d1
WHERE `type` = 'product' AND department IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY(department) ASC
),
ranks = (
SELECT DISTINCT RAW `rank`.level
FROM data AS d1
WHERE `type` = 'product' AND `rank`.level IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY(`rank`.level) ASC
),
category = (
SELECT DISTINCT RAW categories
FROM data AS d1
WHERE `type` = 'product' AND categories IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
),
tags = (
SELECT DISTINCT RAW tag
FROM data AS b
UNNEST b.tags AS tag
WHERE b.`type` = 'product' AND b.tags IS NOT MISSING
AND b.status = 'active' AND b.tenant = 'tenant::bucket'
ORDER BY LOWER(tag)
)
OR
SELECT ARRAY_SORT(ARRAY_AGG (DISTINCT LOWER(brand))) AS brands,
ARRAY_SORT(ARRAY_AGG (DISTINCT department)) AS department,
ARRAY_SORT(ARRAY_AGG (DISTINCT `rank`.level)) AS `rank`,
ARRAY_SORT(ARRAY_DISTINCT(ARRAY_FLATTEN(ARRAY_AGG (ARRAY LOWER(v) FOR v IN tags END),1))) AS tags,
ARRAY_SORT(ARRAY_DISTINCT(ARRAY_FLATTEN(ARRAY_AGG (categories),1))) AS categories
FROM `bucket` AS d
WHERE `type` = 'product' AND status = 'active' AND tenant = 'tenant::bucket'
Hi @vsr1,
I can’t find the logs ( panic and stack trace) about the Error: Panic: runtime error: invalid memory address or nil pointer dereference
It only throws error in our API intermittently. But, when I try query string on the CouchBase Server it runs correctly with no errors. Do you have any idea why this occur? By the way we’re use NodeJS SDK.
Btw, I will try your suggested N1QL query. I hope this would resolved the issue.
If you have more than one query node, check all the nodes (As it depends on which query node it ran the query). (search for panic) panic normally writes in /opt/couchbase/var/lib/couchbase/logs/query.log (if there is compressed query.log check those, too much messages might moved there)
No WHERE clause should be ok. What is version of couchbase.
Try remove one let at a time and see which one causing.
If using 6.5.0 might hitting MB-37365. Add the FROM 1 AS dd before LET
SELECT
brands AS brand,
departments AS department,
ranks AS `rank`,
ARRAY_SORT( ARRAY_DISTINCT( ARRAY_FLATTEN( category, 1 ) ) ) AS categories,
tags
FROM 1 AS dd
LET
brands = (
SELECT DISTINCT RAW LOWER(brand)
FROM `bucket`
WHERE `type` = 'product' AND brand IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY LOWER(brand) ASC
),
departments = (
SELECT DISTINCT RAW department
FROM `bucket`
WHERE `type` = 'product' AND department IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY(department) ASC
),
ranks = (
SELECT DISTINCT RAW `rank`.level
FROM `bucket`
WHERE `type` = 'product' AND `rank`.level IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
ORDER BY(`rank`.level) ASC
),
category = (
SELECT DISTINCT RAW categories
FROM `bucket`
WHERE `type` = 'product' AND categories IS NOT MISSING
AND status = 'active' AND tenant = 'tenant::bucket'
),
tags = (
SELECT DISTINCT RAW tag
FROM `bucket` AS b
UNNEST b.tags AS tag
WHERE b.`type` = 'product' AND b.tags IS NOT MISSING
AND b.status = 'active' AND b.tenant = 'tenant::bucket'
ORDER BY LOWER(tag)
)
basically it is double freeing. You can upgrade latest version. or Add dummy FROM clause (don’t use LET without FROM clause). After change query try kill cbq-engine process (it will restart), so that you don’t see this unexpected error some other scenario.