is it possible to delete multiple table data in single query ?(used database is MEMSQL) - singlestore

i used inner join with delete statement. but i could see the error like "operation delete from multiple table is not allowed".
Delete T1 , T2 from Table1 T1 inner join Table T2
on T1.id =T2.id
where t1.id = 17 ;

No, you can't. See the documentation about the DELETE statement:
Although DELETE supports referencing multiple tables using either joins or subqueries, MemSQL only supports deleting from one table in a DELETE statement.

Related

Cassandra atomicity with delete partition key which belong to different tables

I have a use case where i need to perform delete from three tables in cassandra . The partitioning key is same for all the tables example :-
Db_name/table1/1111
Db_name/table2/1111
Db_name/table3/1111
Which operation i shall use Put/batch in order to maintain the atomicity. I want either all keys to be delete in one go or none is deleted
I need to delete huge no of such keys ..i mean lets say there are 10k such keys which i want to delete from all three tables . It would be something like
Loop over all the keys ..then delete key one by one from three table in one go
You need to use CQL batches to group updates to denormalised tables so they are executed as an atomic operation.
In cqlsh, the batched deletes would look like:
BEGIN BATCH
DELETE FROM table1 WHERE pk = 1111;
DELETE FROM table2 WHERE pk = 1111;
DELETE FROM table3 WHERE pk = 1111;
APPLY BATCH;
You'll need one batch statement for each partition key you are deleting. It's important that you don't group together unrelated partitions in a single batch since CQL batches are NOT an optimisation like it is in RDBMS.
I've explained this in a bit more detail in this article -- How to keep data in denormalized tables in sync. Cheers!

Athena sub-query and LEFT JOIN data scanned optimization

There is a table with parquet data format of 20 GB and simple query will give results by scanning only 1GB of data.
select columns from table1 where id in (id1, id2, idn)
If same query is executed with a sub-query such as -
select columns from table1 where id in (select id from table2 limit n) This query will give results by scanning 20GB, whole the table.Even n is very small number as 10, 50 or 5000.
Same happen with LEFT JOIN.
SELECT table1.* FROM
table2 LEFT JOIN table1
ON table2.id=table1.id
Is there a way to achieve this by running single query instead of fetch and save result of sub-query and pass as args into another query?
Any best practices of How currently users runs LEFT JOIN or sub-query without full table scan on Athena ?
Similar questions- Question -1, Question -2
Is there a way to achieve this by running single query instead of fetch and save result of sub-query and pass as args into another query?
This is most commonly covered by "Dynamic filtering".
Currently there is no way to do this.
Athena is based on Presto and Presto doesn't support dynamic filtering yet, but will likely support it in the next release (Presto 321). You can track the issue here: https://github.com/prestosql/presto/issues/52
Athena is based on Presto 0.172 currently, so it still needs to upgrade.

Spark not allowing separate queries on same data sources within same Spark SQL query

Let's take an example of 2 newly created dataframes empDF and deptDF.
Create a view
empDF.createOrReplaceTempView("table1")
deptDF.createOrReplaceTempView("table2")
spark.sql("select * from table1 as t1
join table2 as t2 on (...) where t1.col1 not in
(select t3.col2 from table1 as t3)"
)
Surprisingly, run time exception occurs complaining "table1" view or table does not exist. This is happening when two different query is performed on same data source.
May I have some idea please.

Reusing subqueries in AWS Athena generate large amount of data scanned

On AWS Athena, I am trying to reuse computed data using a WITH clause, e.g.
WITH temp_table AS (...)
SELECT ...
FROM temp_table t0, temp_table t1, temp_table t2
WHERE ...
If the query is fast, the "Data scanned" goes through the roof. As if temp_table is computed for each time it is reference in the FROM clause.
I don't see the issue if I create a temp table separately and use it multiple times in the query.
Is there a way to really reuse a subquery multiple times without any penalty?

Dynamics AX Nested Query

Maybe I'm missing something simple, but is there a way to write a nested query in AX? I tried some syntax I thought would work, but with no luck.
The following standard SQL statement would accomplish what I'm trying to do, but I need to do this in AX, not SQL.
SELECT table1.column1A, table1.column1B,
(SELECT Top 1 column2B FROM table2
WHERE table1.column1A = table2.column2A
ORDER BY table2.column1A)
AS lookupResult
FROM table1
My problem is that table1 has a one-to-many relationship with table2, and since AX doesn't have a DISTINCT function that I'm aware of, I receive many copies of each record when using a JOIN statement.
Thanks
Nested queries are not supported in AX.
One way to bypass the missing distinct is to use group by (assuming max value of column2B is interesting):
while select column1A, column1B from table1
group column1A, column1B
join max-of(column2B) from table2
where table2.column2A == table1.column1A
{
...
}
Another method would be use a display method on table1 in the form or report.
display ColumnB column2B()
{
return (select max-of(column2B) from table2
where table2.column2A == this.column1A).column2A;
}
The performance is inferior to the first solution, but it may be acceptable.
As mentioned in the previous reply, group-by is the closest you can get to a distinct function. If you need a simpler query for some reason, or if you need a table or query object to use as a datasource on a form or report, you may entertain the idea of creating a view in the AOT, which contains the group-by. You can then use that view to easily join to on a query object or form datasource etc...
Ax2012 has support of computed columns in views, you can use the SysComputedColumn class to build query you want

Resources