GemFire Select * Query with index returns inconsistent results - gemfire

I have a GemFire Query, something like "SELECT * FROM /someregion WHERE fieldX IN SET('123')".
This query returns inconsistent results. For example, it will return the same record many times, etc. If I change the query to "SELECT key FROM /someregion WHERE fieldX IN SET('123')", then I get correct results. I also get correct results if I specify the column name(s) rather than '*'.
Any ideas?

Related

Postgres query cannot find rows based on column value

I want to select rows based on a column value. I know for a fact the column value exists. The first query returns 100 rows from the listing table. The second query, which looks for listings.OriginatingSystemName = 'mfrmls` returns nothing. Why?
(Removing the quotes or using double quotes does not work).
I am using pgAdmin4 to run these queries.
first query:
select * from listing limit 100;
second query:
select * from listing where 'listing.OriginatingSystemName' = 'mfrmls'
This produces a 'column does not exist' error:
select * from listing where OriginatingSystemName = 'mfrmls'
The correct syntax is to just write the column name in your WHERE statement:
SELECT * FROM listings WHERE "OriginatingSystemName" = 'mfrmls';
To elaborate further:
What your original query is doing is selecting every row in the listings table where the text string 'listings.OriginatingSystemName' is equal to this other text string 'mfrmls'. It is not actually grabbing the value from the column you want. No row in the table satisfies your where statement because your where statement is always false. Therefore, no rows are returned but the query was a success.
We need to implement the double quotes when dealing with case-sensitive identifiers. Here is some helpful documentation.

Why The Query Against HashKey returns no records

I am working on a new sql table. The table has a column [varbinary(8000)], where we are storing hash of a certain text. Now, I am trying to retrieve the same record back by using a where clause against the hashkey, but that yields zero records.
I have added a similar query here: http://sqlfiddle.com/#!18/be996/11
Try without the single quotes, like this
SELECT id, description
FROM ForgeRock
where id = 0x94EE059335E587E501CC4BF90613E0814F00A7B08BC7C648FD865A2AF6A22CC2
and you will get the expected result.

Hive LIKE query returns some like results, several unlike results, and some NULL results

When I queried from hive with 'LIKE', it looks like
select * from table where a_column like '%http%';
It returns me some results where a_column does not contain http and some NULL results.
I want to know whether my query sentence is serious or not.
Is there any pattern more seriously?
Please use in the below way using concat_ws.
select * from table where concat_ws(',',map_values(a_column)) like '%http%';

Why do CONTAINS and LIKE return different results?

I have the following query. There are two possible columns that may hold the value I'm looking for, let's call them FieldA and FieldB.
If I execute this:
SELECT COUNT(1)
FROM Table
WHERE CONTAINS(Table.*, 'string')
I get back "0".
However, if I execute this:
SELECT COUNT(1)
FROM TABLE
WHERE FieldA LIKE '%string%' OR FieldB LIKE '%string%'
I get back something like 9000. I then checked and there are rows that have the word string in either FieldA.
Why does this happen? I recall that CONTAINS uses a full-text index, but I also recall that LIKE does the same, so if the problem was that the indexes are outdated, then it should fail for both of them, right?
Thanks
I believe that CONTAINS and full text searching will only yield whole word results, so you won't match the same as LIKE '%string%'. If you want to right wildcard your CONTAINS, you must write it like:
SELECT COUNT(1) FROM Table WHERE CONTAINS(Table.*, '"string*"')
However, if you want to left wildcard, you can't! You have to store a copy of your database reversed and then do:
SELECT COUNT(1) FROM Table WHERE CONTAINS(Table.*, '"gnirts*"')
https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ms552152(v=office.14)
How do you get leading wildcard full-text searches to work in SQL Server?
So in the example in the question, doing a CONTAINS(Table.*, 'string') is not the same as doing LIKE '%string%' and would not have the same results.

Fastest way to check if any case of a pattern exist in a column using SQL

I am trying to write code that allows me to check if there are any cases of a particular pattern inside a table.
The way I am currently doing is with something like
select count(*)
from database.table
where column like (some pattern)
and seeing if the count is greater than 0.
I am curious to see if there is any way I can speed up this process as this type of pattern finding happens in a loop in my query and all I need to know is if there is even one such case rather than the total number of cases.
Any suggestions will be appreciated.
EDIT: I am running this inside a Teradata stored procedure for the purpose of data quality validation.
Using EXISTS will be faster if you don't actually need to know how many matches there are. Something like this would work:
IF EXISTS (
SELECT *
FROM bigTbl
WHERE label LIKE '%test%'
)
SELECT 'match'
ELSE
SELECT 'no match'
This is faster because once it finds a single match it can return a result.
If you don't need the actual count, the most efficient way in Teradata will use EXISTS:
select 1
where exists
( select *
from database.table
where column like (some pattern)
)
This will return an empty result set if the pattern doesn't exist.
In terms of performance, a better approach is to:
select the result set based on your pattern;
limit the result set's size to 1.
Check whether a result was returned.
Doing this prevents the database engine from having to do a full table scan, and the query will return as soon as the first matching record is encountered.
The actual query depends on the database you're using. In MySQL, it would look something like:
SELECT id FROM database.table WHERE column LIKE '%some pattern%' LIMIT 1;
In Oracle it would look like this:
SELECT id FROM database.table WHERE column LIKE '%some pattern%' AND ROWNUM = 1;