OrientDB v2.1.1,
I have tow class: NOrder and NPassenger, relationship 1 : n, so NOrder has a filed named "passengers",whose type is linklist.
I have two fields (NOrder order_id, NPassenger. Name) index is established
NOrder ducuments count is 3 millon .
I explain these query:
1)select from NOrder where passengers contains(name = 'xxx')
why this query not involved index .
2)select from NOrder where 'xxx' in passengers.name
this query involved indexeses
this query cost 120sec .
thanks
I have tried with this structure
create class NPassenger
create property NPassenger.name String
create index NPassenger.name on NPassenger (name) NOTUNIQUE_HASH_INDEX
create class NOrder
create property NOrder.order_id String
create property NOrder.passengers linklist NPassenger
create index NOrder.order_id on NOrder (order_id) UNIQUE_HASH_INDEX
insert into NPassenger(name) values ("xxx") // 12:0
insert into NPassenger(name) values ("Alessandro") //12:1
insert into NOrder(order_id,passengers) values ("order 1",[12:0])
insert into NOrder(order_id,passengers) values ("order 2",[12:1])
Query 1
explain select from NOrder where passengers contains(name = 'xxx')
Query 2
explain select from NOrder where 'xxx' in passengers.name
None of the two queries use the index because the class target is NOrder.
UPDATE
Now I have 50002 NOrder and 50002 NPassenger.
If I execute the queries
explain select from NOrder where passengers contains(name = 'xxx')
and
explain select from NOrder where 'xxx' IN passengers.name'
I get
this is because no index on the name field is used (because the target class is the Norder class) and then the search is done on all 50002 records of the class Norder.
If I use the query
explain select from NPassenger where name = "xxx"
the index NPassenger.name is used because the target class is NPassenger
Related
I would like to have an equivalent Oracle query for the below SQL Query
SQL QUERY:
CREATE UNIQUE NONCLUSTERED INDEX ValidSub_Category ON ValidSub (Category ASC) WHERE (category IS NOT NULL)
purpose: This index is created to make sure that the column has more than 1 NULL records but does not have duplicate strings.
Thanks in advance
I found it
CREATE UNIQUE INDEX VALIDSUB_CATEGORY ON VALIDSUB (Case WHEN Category
IS NOT NULL THEN CATEGORY END);
I have a number of records that are common to all schemas. I place these records in a shared schema table, and would like to inheritthe rows of record from this shared parent table in each of the child schemas.
Suppose I have the following schemas:
CREATE SCHEMA parent;
CREATE SCHEMA a;
CREATE SCHEMA b;
CREATE TABLE parent.component (product_id serial PRIMARY KEY, title text);
CREATE TABLE a.component () INHERITS (parent.component);
CREATE TABLE b.product () INHERITS (parent.component);
INSERT INTO parent.component(title) VALUES ('parent');
INSERT INTO a.component(title) VALUES ('a_test') ,('a_test2') ;
INSERT INTO b.component(title) VALUES ('b_test') ,('b_test2');
Is there a way to select the union of rows from the parent and either a.component or b.component when I issue a select on either a or b ?
So for example:
SELECT * FROM a.component;
returns rows:
id | title
---------------
1 parent
2 a_test
3 a_test2
PostgreSQL has multiple inheritance, so a table can be the child of many tables. You could try to inherit in the other direction!
But maybe a simple UNION ALL query is a simpler and better solution.
I have a query where I'm trying to find a null field from millions of records. There will only be one or two.
The query looks like this:
SELECT *
FROM “table”
WHERE “id” = $1
AND “end_time” IS NULL
ORDER BY “start_time” DESC LIMIT 1
How can I make this query more performant eg using indexes in the database.
try a partial index, smth like:
create index iname on "table" (id, start_time) where end_time is null;
I have tow class: NOrder and NPassenger, relationship 1 : n, so NOrder has a filed named "passengers",whose type is linklist.
I want to select NOrder by NPassenger's field "passengerName",
I used sql
select from NOrder where 'John' in passengers.name
the NOrder ducuments count is 3 millon, this sql works too slowly, how can I do it?
thanks a lot
You can insert an index on the field name of the class NPassenger.
You can use this query
select expand(distinct(rid)) from (FIND REFERENCES (select from NPassenger where name = "John"))
Let me know.
I use some indexes in one file sphinx.conf. When I give result array from these indexes(different tables Mysql) I don't get names of tables. How I can get it?
You can modify sql_query attribute of your indexes in sphinx.conf so they will return one fake attribute - index name.
For example:
first_idx:
...
sql_query = SELECT <...>, 'first_idx' as index_name FROM fisrt_table;
second_idx:
...
sql_query = SELECT <...>, 'second_idx' as index_name FROM second_table;