Orientdb - Match - "The command has not been executed" - orientdb

I have a Orientdb Database with 2 vertex
Pesquisador with 1 million records
Publicacao with 1 million records too
and an Edge COLABORA_COM with 6,239,382
I need select thousand researchers with the highest number of publications.
I execute the command
SELECT psq1.psq_nome AS nomePesquisador, COUNT(pub1) AS qtdPub
FROM (
MATCH
{class:Pesquisador, as:psq1}.outE("PUBLICOU").inV(){as:pub1}
RETURN psq1, pub1
)
GROUP BY psq1
ORDER BY qtdPub DESC, nomePesquisador
LIMIT 1000;
then thera are the error "The command has not been executed"
if I limit the MATCH RETURN to 250000 records (RETURN psq1, pub1 LIMIT 250000) the match execute with no errors
is there an error of memory?

Related

How do i limit the number of rows updated in postgres

I am trying to update records in customer table by limiting them to n number of records but i am having an error when i am using offset and limit keywords.
Where do i put
offset 0 limit 1
in update statement sub query as the sub query is like:
update customer set name = 'sample name' where customer_id in (142, 143, 144, 145 offset 0 limit 1);
When i tried executing update statement above, i get an error:
ERROR: syntax error at or near "offset"
Note: limit does not have to be 1, it can be any number and same is true for offset
offset and limit work on rows, not on a list.
You can transform the in() clause to use a subquery that return a row from each of your input
update customer
set name = 'sample name'
where customer_id in (select unnest(array[142, 143, 144, 145]) offset 0 limit 1);

The command has not been executed - Republicated With New Informations - MATCH Clause

I have a Orientdb Database with 2 vertex
Pesquisador with 1 million records
Publicacao with 1 million records too
and an Edge COLABORA_COM with 6,239,382
I need select thousand researchers with the highest number of publications.
I execute the command
SELECT psq1.psq_nome AS nomePesquisador, COUNT(pub1) AS qtdPub
FROM (
MATCH
{class:Pesquisador, as:psq1}.outE("PUBLICOU").inV(){as:pub1}
RETURN psq1, pub1
)
GROUP BY psq1
ORDER BY qtdPub DESC, nomePesquisador
LIMIT 1000;
then there are the error "The command has not been executed"
But if a execute the query
SELECT ordem, out.psq_nome, out.psq_data_nascimento
FROM PUBLICOU
WHERE in.pub_id = 5022
ORDER BY ordem;
the query execute ok
is there an error of memory with MATCH?
Should I change the memory settings?

comprare aggregate sum function to number in postgres

I have the next query which does not work:
UPDATE item
SET popularity= (CASE
WHEN (select SUM(io.quantity) from item i NATURAL JOIN itemorder io GROUP BY io.item_id) > 3 THEN TRUE
ELSE FALSE
END);
Here I want to compare each line of inner SELECT SUM value with 3 and update popularity. But SQL gives error:
ERROR: more than one row returned by a subquery used as an expression
I understand that inner SELECT returns many values, but can smb help me in how to compare each line. In other words make loop.
When using a subquery you need to get a single row back, so you're effectively doing a query for each record in the item table.
UPDATE item i
SET popularity = (SELECT SUM(io.quantity) FROM itemorder io
WHERE io.item_id = i.item_id) > 3;
An alternative (which is a postgresql extension) is to use a derived table in a FROM clause.
UPDATE item i2
SET popularity = x.orders > 3
FROM (select i.item_id, SUM(io.quantity) as orders
from item i NATURAL JOIN itemorder io GROUP BY io.item_id)
as x(item_id,orders)
WHERE i2.item_id = x.item_id
Here you're doing a single group clause as you had, and we're joining the table to be updated with the results of the group.

T-SQL Query to process data in batches without breaking groups

I am using SQL 2008 and trying to process the data I have in a table in batches, however, there is a catch. The data is broken into groups and, as I do my processing, I have to make sure that a group will always be contained within a batch or, in other words, that the group will never be split across different batches. It's assumed that the batch size will always be much larger than the group size. Here is the setup to illustrate what I mean (the code is using Jeff Moden's data generation logic: http://www.sqlservercentral.com/articles/Data+Generation/87901)
DECLARE #NumberOfRows INT = 1000,
#StartValue INT = 1,
#EndValue INT = 500,
#Range INT
SET #Range = #EndValue - #StartValue + 1
IF OBJECT_ID('tempdb..#SomeTestTable','U') IS NOT NULL
DROP TABLE #SomeTestTable;
SELECT TOP (#NumberOfRows)
GroupID = ABS(CHECKSUM(NEWID())) % #Range + #StartValue
INTO #SomeTestTable
FROM sys.all_columns ac1
CROSS JOIN sys.all_columns ac2
This will create a table with about 435 groups of records containing between 1 and 7 records in each. Now, let's say I want to process these records in batches of 100 records per batch. How can I make sure that my GroupID's don't get split between different batches? I am fine if each batch is not exactly 100 records, it could be a little more or a little less.
I appreciate any suggestions!
This will result in slightly smaller batches than 100 entries, it'll remove all groups that aren't entirely in the selection;
WITH cte AS (SELECT TOP 100 * FROM (
SELECT GroupID, ROW_NUMBER() OVER (PARTITION BY GroupID ORDER BY GroupID) r
FROM #SomeTestTable) a
ORDER BY GroupID, r DESC)
SELECT c1.GroupID FROM cte c1
JOIN cte c2
ON c1.GroupID = c2.GroupID
AND c2.r = 1
It'll select the groups with the lowest GroupID's, limited to 100 entries into a common table expression along with the row number, then it'll use the row number to throw away any groups that aren't entirely in the selection (row number 1 needs to be in the selection for the group to be, since the row number is ordered descending before cutting with TOP).

T SQL Group By Having Count of returning wrong data

I have a complex t-sql query "for me anyway" that isn't functioning the way I need it to.
The query is designed to return simular records unioned across two databases that have simular records in each database.
If a product fails, it will be assigned a "Failed" in one DB, or a "PF" in the other DB. "PR" means "PRODUCT READY" in both.
I am trying to return a list that includes only "Failed or PF" data that has < two records based on the ProdNo column.
"This is to prompt the employee to test the product again", if 2 records exist in either DB, no action is needed."
My query breaks down when I try to limit the results to show only entries that have less than 2 duplicate "ProdNo" values.
In other words, a product is produced and given a ProdNo number. After testing, it can be marked as a PR, PF, or Failed.
My query should never produce any results with PR, yet when a test is performed several days after the original test, PR values appear in my results.
Here is the query with notes.
-- 1st half of union query
-- Find all run failed's that do not have a PR'ed 2nd test.
Declare #daysback int
set #daysback = -2
select min(sid3)as 'ProdNo',
min([Timestamp])as 'TimeS',
min(Burn) as 'type',
min(Mixer) as 'Mixer'
from [Stat].[dbo].[oedata]
where sid3 IN
(
-- Find run faileds and PRs in Stat db
SELECT [sid3]
from [Stat].[dbo].[oedata]
where (type ='wos') and (burn = 'failed')
and (Flag = '128')
)
--- Limit Results to return only instances of 1 record
AND [Timestamp] > DATEADD( d, #daysback, getdate())
group by Sid3
having COUNT(Sid3) = 1
union all
-- Find PF's in CompanyMES MLab DB
select min(mProd_ProdNumber)as 'ProdNo',
min([Timestamp])as 'TimeS',
min(CheckType) as 'type',
min(Mixer) as 'Mixer'
from [CompanyMES].[dbo].[mLab]
where mProd_ProdNumber IN
(
-- Find failed DFs or scrap wos products
SELECT [mProd_ProdNumber]
from [CompanyMES].[dbo].[mLab]
where (CheckType = 'PF' )
)
-- Limit Results to instances with only 1 record
AND [Timestamp] > DATEADD( d, #daysback, getdate())
group by mProd_ProdNumber
having COUNT(mProd_ProdNumber) < 2
order by TimeS Desc
--------------------------------------------------------------------------
Example data and results:
ProdNo Type
=================
'1111' 'PF'
'1111' 'PR'
'1112' 'PR'
'1113' 'PF'
'1114' 'Failed'
ProdNo 1111 shouldn't return anything as it has 2 records as well as a PR exists.
1113 and 1114 should return results as they both have only 1 record as well as have PF and Failed Types
I think the issue is that you are applying a filter on the Timestamp in your outer queries, but not the inner one where you are filtering the Product Numbers. So, for 1111 and 1112, it could have a 'PF' (or 'Failed') outside of your timestamp filtered range, but only 'PR' inside of it (in one of the tables).