Apache ignite query not working well with index - ignite

I upload the data in ignite 3 cache and total data around 1 million in all 3 caches.while i run query on it i got result in 1s and its generate below query plan
SELECT DISTINCT
A3.VAL2 AS __C0
FROM DPHAF.DPHAF A1
/* DPHAF.DPHAF.__SCAN_ */
/* WHERE (A1.VAL0 = 'dg~')
AND ((A1.PROP6 = '1oh~#has_single_bond')
AND (A1.PROP0 = '4xm~#type'))
*/
INNER JOIN DS_AF.DS_AF S1
/* DS_AF."prop_asc_entity_asc_elem_asc_typ_asc_idx": PROP = A1.PROP6
AND ENTITY = A1.ENTRY
*/
ON 1=1
/* WHERE (A1.PROP6 = S1.PROP)
AND (A1.ENTRY = S1.ENTITY)
*/
INNER JOIN DPHAF.DPHAF A2
/* DPHAF."entry_asc_idx": ENTRY = S1.ELEM */
ON 1=1
/* WHERE (S1.ELEM = A2.ENTRY)
AND ((A2.PROP0 = '4xm~#type')
AND ((A2.PROP6 = '1oh~#has_single_bond')
AND (A2.VAL0 = '7a~')))
*/
INNER JOIN DS_AF.DS_AF S2
/* DS_AF."prop_asc_entity_asc_elem_asc_typ_asc_idx": PROP = A2.PROP6
AND ENTITY = A2.ENTRY
*/
ON 1=1
/* WHERE (A2.PROP6 = S2.PROP)
AND (A2.ENTRY = S2.ENTITY)
*/
INNER JOIN DPHAF.DPHAF A3
/* DPHAF."entry_asc_idx": ENTRY = S2.ELEM */
ON 1=1
WHERE (A3.PROP2 = '1oh~#is_atom_of')
AND ((A3.VAL0 = '7a~')
AND ((A3.PROP0 = '4xm~#type')
AND ((S2.ELEM = A3.ENTRY)
AND ((A2.PROP6 = S2.PROP)
AND ((A2.PROP6 = '1oh~#has_single_bond')
AND ((A2.ENTRY = S2.ENTITY)
AND ((A2.VAL0 = '7a~')
AND ((A2.PROP0 = '4xm~#type')
AND ((S1.ELEM = A2.ENTRY)
AND ((A1.PROP6 = S1.PROP)
AND ((A1.PROP6 = '1oh~#has_single_bond')
AND ((A1.ENTRY = S1.ENTITY)
AND ((A1.PROP0 = '4xm~#type')
AND (A1.VAL0 = 'dg~'))))))))))))))
LIMIT 1000
SELECT DISTINCT
__C0 AS VAL2
FROM PUBLIC.__T0
/* DPHAF."merge_scan" */
LIMIT 1000
as you notice there is full cache scan here /* DPHAF.DPHAF.__SCAN_ */
After that when we add index on DPHAF group index it will give us below plan
SELECT
A1.VAL2 AS __C0
FROM DPHAF.DPHAF A1
/* DPHAF."prop0_asc_val0_asc_idx": VAL0 = '7a~'
AND PROP0 = '4xm~#type'
*/
/* WHERE (A1.PROP0 = '4xm~#type')
AND ((A1.PROP2 = '1oh~#is_atom_of')
AND ((A1.VAL0 = '7a~')
AND ((A1.VAL5 = '3')
AND ((A1.PROP8 = '1oh~#has_double_bond')
AND (A1.PROP6 = '1oh~#has_single_bond')))))
*/
INNER JOIN DPHAF.DPHAF A3
/* DPHAF."prop0_asc_val0_asc_idx": VAL0 = '7a~'
AND PROP0 = '4xm~#type'
*/
ON 1=1
/* WHERE (A3.PROP0 = '4xm~#type')
AND ((A3.VAL5 = '1')
AND (A3.VAL0 = '7a~'))
*/
INNER JOIN DPHAF.DPHAF A4
/* DPHAF."prop0_asc_val0_asc_idx": VAL0 = '562~'
AND PROP0 = '4xm~#type'
*/
ON 1=1
/* WHERE (A4.PROP0 = '4xm~#type')
AND ((A4.VAL5 = '1')
AND (A4.VAL0 = '562~'))
*/
INNER JOIN DS_AF.DS_AF S1
/* DS_AF."prop_asc_entity_asc_elem_asc_typ_asc_idx": PROP = A1.PROP6
AND ENTITY = A1.ENTRY
*/
ON 1=1
/* WHERE (A1.PROP6 = S1.PROP)
AND (A1.ENTRY = S1.ENTITY)
*/
INNER JOIN DPHAF.DPHAF A2
/* DPHAF."entry_asc_idx": ENTRY = S1.ELEM */
ON 1=1
/* WHERE (S1.ELEM = A2.ENTRY)
AND ((A2.VAL5 = '1')
AND (A2.VAL0 = '562~'))
*/
INNER JOIN DS_AF.DS_AF S2
/* DS_AF."prop_asc_elem_asc_entity_asc_typ_asc_idx": ELEM = A3.ENTRY
AND PROP = A1.PROP6
AND ENTITY = A1.ENTRY
*/
ON 1=1
/* WHERE (A1.ENTRY = S2.ENTITY)
AND ((S2.ELEM = A3.ENTRY)
AND (A1.PROP6 = S2.PROP))
*/
INNER JOIN DS_AF.DS_AF D1
/* DS_AF."prop_asc_elem_asc_entity_asc_typ_asc_idx": ELEM = A4.ENTRY
AND PROP = A1.PROP8
AND ENTITY = A1.ENTRY
*/
ON 1=1
WHERE (A4.VAL5 = '1')
AND ((A4.VAL0 = '562~')
AND ((A4.PROP0 = '4xm~#type')
AND ((D1.ELEM = A4.ENTRY)
AND ((A1.PROP8 = D1.PROP)
AND ((A1.PROP8 = '1oh~#has_double_bond')
AND ((A1.ENTRY = D1.ENTITY)
AND ((A3.VAL5 = '1')
AND ((A3.VAL0 = '7a~')
AND ((A3.PROP0 = '4xm~#type')
AND ((S2.ELEM = A3.ENTRY)
AND ((A1.PROP6 = S2.PROP)
AND ((A1.ENTRY = S2.ENTITY)
AND ((A2.VAL5 = '1')
AND ((A2.VAL0 = '562~')
AND ((S1.ELEM = A2.ENTRY)
AND ((A1.PROP6 = S1.PROP)
AND ((A1.PROP6 = '1oh~#has_single_bond')
AND ((A1.ENTRY = S1.ENTITY)
AND ((A1.VAL5 = '3')
AND ((A1.VAL0 = '7a~')
AND ((A1.PROP2 = '1oh~#is_atom_of')
AND (A1.PROP0 = '4xm~#type'))))))))))))))))))))))
SELECT
__C0 AS VAL2
FROM PUBLIC.__T0
/* DPHAF."merge_scan" */
Here you can see we dont have full scan of DPHAF but my query is running for soo long or infinite so am i do anything wrong?
Thanks

It is best if you ask this question at Ignite user forum. It requires debugging to get to the bottom of it.

Related

Why is DMux4way operate like this?

When the sel is 01 the b should be chosen, but why the operation is a = nsel1 b = sel[0]? After that the sel will become 00 from 01
CHIP DMux4Way {
IN in, sel[2];
OUT a, b, c, d;
PARTS:
// Put your code here:
Not(in = sel[0], out = nsel0);
Not(in = sel[1], out = nsel1);
And(a = nsel1, b = nsel0, out = s00);
And(a = in, b = s00, out = a);
And(a = nsel1, b = sel[0], out = s01);
And(a = in, b = s01, out = b);
And(a = sel[1], b = nsel0, out = s10);
And(a = in, b = s10, out = c);
And(a = sel[1], b = sel[0], out = s11);
And(a = in, b = s11, out = d);
}
I just figured it out because the hack uses little endian.
In each pair of ANDs, the first one determines whether the output is activated, and the second one gates the input to that output.
So:
And(a = nsel1, b = nsel0, out = s00);
s00 is True only if both its inputs (nsel0 and nsel1) are True. Since they are the inverse of sel[0] and sel[1], s00 will only be true if both sel[0] and sel[1] are False.
And(a = in, b = s00, out = a);
The second And will only be true if both in and s00 are True. So it will only be True if in is True, and sel[0] and sel[1] are False.
Similar logic applies for the other cases. But the key point is that for the 01 and 10 cases, it is not enough to check that the right value is True, you also have to check that the other value is 0.
Edit: In addition, as the OP points out in a subsequent comment, the machine is little-endian, and you must keep this in mind when operating on a multi-bit bus (like sel).

How can I use the IF in Firebird with a stored procedure?

I'm trying to write an IF statement in my stored procedure, but I have no idea how.
TIPO_DOCUMENTO can be 'FAC' or 'DEV', if TIPO_DOCUMENTO is 'FAC', I will use the total_neto, total_impuesto, total, costo and precio as is. But if I have 'DEV', I will need the negative values of those fields.
begin
/*FILTRO RANGO DE FECHA*/
IF (P_FECHA_DESDE='0' OR (P_FECHA_DESDE IS NULL) OR (P_FECHA_DESDE='')) THEN
V_FECHA_DESDE = CAST('01/01/1900' AS DATE);
ELSE
V_FECHA_DESDE = CAST(:P_FECHA_DESDE AS DATE);
IF (P_FECHA_HASTA='0' OR (P_FECHA_HASTA IS NULL)OR (P_FECHA_HASTA='')) THEN
V_FECHA_HASTA = CAST('12/31/3999' AS DATE);
ELSE
V_FECHA_HASTA = CAST(:P_FECHA_HASTA AS DATE);
/*FILTRO RANGO DE VENDEDORES*/
IF (P_VENDEDOR_DESDE IS NULL) THEN P_VENDEDOR_DESDE = '';
IF (P_VENDEDOR_HASTA IS NULL) THEN P_VENDEDOR_HASTA = LOWER('ZZZZZZZZZZZZZZZ');
IF (P_VENDEDOR_HASTA = '') THEN P_VENDEDOR_HASTA = LOWER('ZZZZZZZZZZZZZZZ');
IF (NOT ((P_VENDEDOR_DESDE = '') AND (P_VENDEDOR_HASTA = LOWER('ZZZZZZZZZZZZZZZ')))) THEN
IF (P_VENDEDOR_DESDE = P_VENDEDOR_HASTA) THEN
V_WHERE = V_WHERE || ' AND (VEN.VENDEDOR_CODIGO = '''||P_VENDEDOR_DESDE||''')';
ELSE
V_WHERE = V_WHERE || ' AND (VEN.VENDEDOR_CODIGO BETWEEN '''||P_VENDEDOR_DESDE||''' AND '''||P_VENDEDOR_HASTA||''')';
/*CICLO DE LA CONSULTA SQL*/
FOR SELECT
a.tipo_documento,
a.documento,
b.nombre as vendedor,
c.producto_codigo,
c.producto_nombre as descripcion,
c.cantidad,
d.departamento_codigo,
c.deposito_codigo,
(c.descuento_unitario * c.cantidad) + (c.descuento_unitario_2 * c.cantidad) + (c.descuento_unitario_3 * c.cantidad) +(c.descuento_unitario_4 * c.cantidad) as total_descuento,
c.total_neto,
c.total_impuesto,
c.total,
a.cliente_codigo,
a.cliente_nombre,
e.direccion,
estado.nombre,
ciudad.nombre,
c.costo_unitario * c.cantidad as costo,
c.precio_unitario * c.cantidad as precio
from ventas a
join vendedores b
on a.vendedor_codigo = b.codigo
join ventas_detalles c
on a.correlativo = c.correlativo_principal
join productos_terminados d
on d.codigo_producto = c.producto_codigo
join clientes e
on a.cliente_codigo = e.codigo
join ubicacion_geografica estado
on estado.codigo = e.estado
and estado.tipo = 'E'
join ubicacion_geografica ciudad
on ciudad.codigo = e.ciudad
and ciudad.tipo = 'C'
where a.fecha_emision between :V_FECHA_DESDE and :V_FECHA_HASTA
INTO
:TIPO_DOC,
:NUM_DOC,
:VENDEDOR_NOMBRE,
:PRODUCTO_CODIGO,
:PRODUCTO_NOMBRE,
:CANTIDAD,
:DEPARTAMENTO,
:DEPOSITO,
:DESCUENTO,
:TOTAL_NETO,
:TOTAL_IMPUESTO,
:TOTAL,
:CLIENTE_CODIGO,
:CLIENTE_NOMBRE,
:CLIENTE_DIRECCION,
:ESTADO,
:CIUDAD,
:COSTO,
:PRECIO
do
begin
if (TIPO_DOC = 'DEV') then
total_neto = -total_neto ;
total_impuesto = -total_impuesto ;
total = -total ;
costo = -costo ;
precio = -precio;
suspend;
end
end
Now I can only get the negative values, regardless of whether I have FAC or DEV.
Your if is syntactically wrong for what I think you want to do. The indentation of the following suggests that all those statements should depend on the if condition:
if (TIPO_DOC = 'DEV') then
total_neto = -total_neto ;
total_impuesto = -total_impuesto ;
total = -total ;
costo = -costo ;
precio = -precio;
In reality only the first statement after the if belongs to the if condition. In other words, it is actually
if (TIPO_DOC = 'DEV') then
total_neto = -total_neto ;
total_impuesto = -total_impuesto ;
total = -total ;
costo = -costo ;
precio = -precio;
If you want all those statements to depend on the if, you need to define a block using begin and end:
if (TIPO_DOC = 'DEV') then
begin
total_neto = -total_neto ;
total_impuesto = -total_impuesto ;
total = -total ;
costo = -costo ;
precio = -precio;
end
See also IF ... THEN ... ELSE in the Firebird 2.5 Language Reference.
Not an answer, just an advice, using syntactic highlighting.
FOR SELECT
....
do
if (TIPO_DOC = 'DEV') then
total_neto = -total_neto ;
total_impuesto = -total_impuesto ;
total = -total ;
costo = -costo ;
precio = -precio;
This code has few problems with me.
If within loop - often it may slow down execution. So if IF condition is not dependent upon loop data - if it is invariant - it might make sense to move If outside of loop.
Future compatibility - what would you procedure do if for example TIPO_DOCUMENTO = 'BE-BE-BE'? Should not happen today? But it can happen tomorrow as new functions would be added to the program. It even can happen today because of some bug.
Personally i would do it different way:
DECLARE VARIABLE COEFF SMALLINT;
....
COEFF = CASE TIPO_DOC
WHEN 'DEV' THEN -1
WHEN 'FAC' THEN +1
ELSE :COEFF / 0 /* generate error if prohibited value */
END;
-- shorthand
-- COEFF = DECODE( TIPO_DOC, 'DEV',-1, 'FAC',+1, :COEFF / 0 );
FOR SELECT....
DO
total_neto = COEFF*total_neto ;
total_impuesto = COEFF*total_impuesto;
....
More strange things: P_VENDEDOR_DESDE = ''; - thus this variable is some text type, like VarChar or CHAR or BLOB SUB_TYPE TEXT.
Then why VEN.VENDEDOR_CODIGO BETWEEN '''||P_VENDEDOR_DESDE||''' AND '''||P_VENDEDOR_HASTA||''' ???
Why not just VEN.VENDEDOR_CODIGO BETWEEN P_VENDEDOR_DESDE AND P_VENDEDOR_HASTA ?

Does Field order matter in an inner join for access SQL?

I have a query that requires ONE HUNDRED fields to be joined from one table to another. instead of manually going through the query designer, i decided to build the join using excel. When i put the code in to the SQL side of the query, then clicked designer, it choked on all 100 field comparisons and removed them. i proceeded to manually click drag the entire set of 100 field to join them all. somehow it worked. now when i look at the sql code for how access did it, it looks almost identical to my code. the only difference that i can identify is that instead of it going from A-Z, it goes Z-A.
Original Query
PARAMETERS pn TEXT (255)
,tt TEXT (255)
,sns Long
,sne Long
,ds DATETIME
,de DATETIME;
SELECT y.Short_Description1
,y.Data1
,y.Short_Description2
,y.Data2
,y.Short_Description3
,y.Data3
,y.Short_Description4
,y.Data4
,y.Short_Description5
,y.Data5
,y.Short_Description6
,y.Data6
,y.Short_Description7
,y.Data7
,y.Short_Description8
,y.Data8
,y.Short_Description9
,y.Data9
,y.Short_Description10
,y.Data10
,y.Short_Description11
,y.Data11
,y.Short_Description12
,y.Data12
,y.Short_Description13
,y.Data13
,y.Short_Description14
,y.Data14
,y.Short_Description15
,y.Data15
,y.Short_Description16
,y.Data16
,y.Short_Description17
,y.Data17
,y.Short_Description18
,y.Data18
,y.Short_Description19
,y.Data19
,y.Short_Description20
,y.Data20
,y.Short_Description21
,y.Data21
,y.Short_Description22
,y.Data22
,y.Short_Description23
,y.Data23
,y.Short_Description24
,y.Data24
,y.Short_Description25
,y.Data25
,y.Short_Description26
,y.Data26
,y.Short_Description27
,y.Data27
,y.Short_Description28
,y.Data28
,y.Short_Description29
,y.Data29
,y.Short_Description30
,y.Data30
,y.Short_Description31
,y.Data31
,y.Short_Description32
,y.Data32
,y.Short_Description33
,y.Data33
,y.Short_Description34
,y.Data34
,y.Short_Description35
,y.Data35
,y.Short_Description36
,y.Data36
,y.Short_Description37
,y.Data37
,y.Short_Description38
,y.Data38
,y.Short_Description39
,y.Data39
,y.Short_Description40
,y.Data40
,y.Short_Description41
,y.Data41
,y.Short_Description42
,y.Data42
,y.Short_Description43
,y.Data43
,y.Short_Description44
,y.Data44
,y.Short_Description45
,y.Data45
,y.Short_Description46
,y.Data46
,y.Short_Description47
,y.Data47
,y.Short_Description48
,y.Data48
,y.Short_Description49
,y.Data49
,y.Short_Description50
,y.Data50
,y.Short_Description51
,y.Data51
,y.Short_Description52
,y.Data52
,y.Short_Description53
,y.Data53
,y.Short_Description54
,y.Data54
,y.Short_Description55
,y.Data55
,y.Short_Description56
,y.Data56
,y.Short_Description57
,y.Data57
,y.Short_Description58
,y.Data58
,y.Short_Description59
,y.Data59
,y.Short_Description60
,y.Data60
,y.Short_Description61
,y.Data61
,y.Short_Description62
,y.Data62
,y.Short_Description63
,y.Data63
,y.Short_Description64
,y.Data64
,y.Short_Description65
,y.Data65
,y.Short_Description66
,y.Data66
,y.Short_Description67
,y.Data67
,y.Short_Description68
,y.Data68
,y.Short_Description69
,y.Data69
,y.Short_Description70
,y.Data70
,y.Short_Description71
,y.Data71
,y.Short_Description72
,y.Data72
,y.Short_Description73
,y.Data73
,y.Short_Description74
,y.Data74
,y.Short_Description75
,y.Data75
,y.Short_Description76
,y.Data76
,y.Short_Description77
,y.Data77
,y.Short_Description78
,y.Data78
,y.Short_Description79
,y.Data79
,y.Short_Description80
,y.Data80
,y.Short_Description81
,y.Data81
,y.Short_Description82
,y.Data82
,y.Short_Description83
,y.Data83
,y.Short_Description84
,y.Data84
,y.Short_Description85
,y.Data85
,y.Short_Description86
,y.Data86
,y.Short_Description87
,y.Data87
,y.Short_Description88
,y.Data88
,y.Short_Description89
,y.Data89
,y.Short_Description90
,y.Data90
,y.Short_Description91
,y.Data91
,y.Short_Description92
,y.Data92
,y.Short_Description93
,y.Data93
,y.Short_Description94
,y.Data94
,y.Short_Description95
,y.Data95
,y.Short_Description96
,y.Data96
,y.Short_Description97
,y.Data97
,y.Short_Description98
,y.Data98
,y.Short_Description99
,y.Data99
,y.Short_Description100
,y.Data100
,x.rownum
FROM qryIndividualTestData100Descriptions AS x
INNER JOIN IndividualTestData100 AS y ON (x.Short_Description1 =
y.Short_Description1)
AND (x.Short_Description2 = y.Short_Description2)
AND (x.Short_Description3 = y.Short_Description3)
AND (x.Short_Description4 = y.Short_Description4)
AND (x.Short_Description5 = y.Short_Description5)
AND (x.Short_Description6 = y.Short_Description6)
AND (x.Short_Description7 = y.Short_Description7)
AND (x.Short_Description8 = y.Short_Description8)
AND (x.Short_Description9 = y.Short_Description9)
AND (x.Short_Description10 = y.Short_Description10)
AND (x.Short_Description11 = y.Short_Description11)
AND (x.Short_Description12 = y.Short_Description12)
AND (x.Short_Description13 = y.Short_Description13)
AND (x.Short_Description14 = y.Short_Description14)
AND (x.Short_Description15 = y.Short_Description15)
AND (x.Short_Description16 = y.Short_Description16)
AND (x.Short_Description17 = y.Short_Description17)
AND (x.Short_Description18 = y.Short_Description18)
AND (x.Short_Description19 = y.Short_Description19)
AND (x.Short_Description20 = y.Short_Description20)
AND (x.Short_Description21 = y.Short_Description21)
AND (x.Short_Description22 = y.Short_Description22)
AND (x.Short_Description23 = y.Short_Description23)
AND (x.Short_Description24 = y.Short_Description24)
AND (x.Short_Description25 = y.Short_Description25)
AND (x.Short_Description26 = y.Short_Description26)
AND (x.Short_Description27 = y.Short_Description27)
AND (x.Short_Description28 = y.Short_Description28)
AND (x.Short_Description29 = y.Short_Description29)
AND (x.Short_Description30 = y.Short_Description30)
AND (x.Short_Description31 = y.Short_Description31)
AND (x.Short_Description32 = y.Short_Description32)
AND (x.Short_Description33 = y.Short_Description33)
AND (x.Short_Description34 = y.Short_Description34)
AND (x.Short_Description35 = y.Short_Description35)
AND (x.Short_Description36 = y.Short_Description36)
AND (x.Short_Description37 = y.Short_Description37)
AND (x.Short_Description38 = y.Short_Description38)
AND (x.Short_Description39 = y.Short_Description39)
AND (x.Short_Description40 = y.Short_Description40)
AND (x.Short_Description41 = y.Short_Description41)
AND (x.Short_Description42 = y.Short_Description42)
AND (x.Short_Description43 = y.Short_Description43)
AND (x.Short_Description44 = y.Short_Description44)
AND (x.Short_Description45 = y.Short_Description45)
AND (x.Short_Description46 = y.Short_Description46)
AND (x.Short_Description47 = y.Short_Description47)
AND (x.Short_Description48 = y.Short_Description48)
AND (x.Short_Description49 = y.Short_Description49)
AND (x.Short_Description50 = y.Short_Description50)
AND (x.Short_Description51 = y.Short_Description51)
AND (x.Short_Description52 = y.Short_Description52)
AND (x.Short_Description53 = y.Short_Description53)
AND (x.Short_Description54 = y.Short_Description54)
AND (x.Short_Description55 = y.Short_Description55)
AND (x.Short_Description56 = y.Short_Description56)
AND (x.Short_Description57 = y.Short_Description57)
AND (x.Short_Description58 = y.Short_Description58)
AND (x.Short_Description59 = y.Short_Description59)
AND (x.Short_Description60 = y.Short_Description60)
AND (x.Short_Description61 = y.Short_Description61)
AND (x.Short_Description62 = y.Short_Description62)
AND (x.Short_Description63 = y.Short_Description63)
AND (x.Short_Description64 = y.Short_Description64)
AND (x.Short_Description65 = y.Short_Description65)
AND (x.Short_Description66 = y.Short_Description66)
AND (x.Short_Description67 = y.Short_Description67)
AND (x.Short_Description68 = y.Short_Description68)
AND (x.Short_Description69 = y.Short_Description69)
AND (x.Short_Description70 = y.Short_Description70)
AND (x.Short_Description71 = y.Short_Description71)
AND (x.Short_Description72 = y.Short_Description72)
AND (x.Short_Description73 = y.Short_Description73)
AND (x.Short_Description74 = y.Short_Description74)
AND (x.Short_Description75 = y.Short_Description75)
AND (x.Short_Description76 = y.Short_Description76)
AND (x.Short_Description77 = y.Short_Description77)
AND (x.Short_Description78 = y.Short_Description78)
AND (x.Short_Description79 = y.Short_Description79)
AND (x.Short_Description80 = y.Short_Description80)
AND (x.Short_Description81 = y.Short_Description81)
AND (x.Short_Description82 = y.Short_Description82)
AND (x.Short_Description83 = y.Short_Description83)
AND (x.Short_Description84 = y.Short_Description84)
AND (x.Short_Description85 = y.Short_Description85)
AND (x.Short_Description86 = y.Short_Description86)
AND (x.Short_Description87 = y.Short_Description87)
AND (x.Short_Description88 = y.Short_Description88)
AND (x.Short_Description89 = y.Short_Description89)
AND (x.Short_Description90 = y.Short_Description90)
AND (x.Short_Description91 = y.Short_Description91)
AND (x.Short_Description92 = y.Short_Description92)
AND (x.Short_Description93 = y.Short_Description93)
AND (x.Short_Description94 = y.Short_Description94)
AND (x.Short_Description95 = y.Short_Description95)
AND (x.Short_Description96 = y.Short_Description96)
AND (x.Short_Description97 = y.Short_Description97)
AND (x.Short_Description98 = y.Short_Description98)
AND (x.Short_Description99 = y.Short_Description99)
AND (x.Short_Description100 = y.Short_Description100)
WHERE (
((y.[Part_Number]) LIKE [pn] & "*" & [tt])
AND (
(y.[Serial_Number]) >= [sns]
AND (y.[Serial_Number]) <= [sne]
)
AND (
(y.[Test_Date]) >= [ds]
AND (y.[Test_Date]) <= [de]
)
);
Access Generated version
PARAMETERS pn TEXT (255)
,tt TEXT (255)
,sns Long
,sne Long
,ds DATETIME
,de DATETIME;
SELECT y.Short_Description1
,y.Data1
,y.Short_Description2
,y.Data2
,y.Short_Description3
,y.Data3
,y.Short_Description4
,y.Data4
,y.Short_Description5
,y.Data5
,y.Short_Description6
,y.Data6
,y.Short_Description7
,y.Data7
,y.Short_Description8
,y.Data8
,y.Short_Description9
,y.Data9
,y.Short_Description10
,y.Data10
,y.Short_Description11
,y.Data11
,y.Short_Description12
,y.Data12
,y.Short_Description13
,y.Data13
,y.Short_Description14
,y.Data14
,y.Short_Description15
,y.Data15
,y.Short_Description16
,y.Data16
,y.Short_Description17
,y.Data17
,y.Short_Description18
,y.Data18
,y.Short_Description19
,y.Data19
,y.Short_Description20
,y.Data20
,y.Short_Description21
,y.Data21
,y.Short_Description22
,y.Data22
,y.Short_Description23
,y.Data23
,y.Short_Description24
,y.Data24
,y.Short_Description25
,y.Data25
,y.Short_Description26
,y.Data26
,y.Short_Description27
,y.Data27
,y.Short_Description28
,y.Data28
,y.Short_Description29
,y.Data29
,y.Short_Description30
,y.Data30
,y.Short_Description31
,y.Data31
,y.Short_Description32
,y.Data32
,y.Short_Description33
,y.Data33
,y.Short_Description34
,y.Data34
,y.Short_Description35
,y.Data35
,y.Short_Description36
,y.Data36
,y.Short_Description37
,y.Data37
,y.Short_Description38
,y.Data38
,y.Short_Description39
,y.Data39
,y.Short_Description40
,y.Data40
,y.Short_Description41
,y.Data41
,y.Short_Description42
,y.Data42
,y.Short_Description43
,y.Data43
,y.Short_Description44
,y.Data44
,y.Short_Description45
,y.Data45
,y.Short_Description46
,y.Data46
,y.Short_Description47
,y.Data47
,y.Short_Description48
,y.Data48
,y.Short_Description49
,y.Data49
,y.Short_Description50
,y.Data50
,y.Short_Description51
,y.Data51
,y.Short_Description52
,y.Data52
,y.Short_Description53
,y.Data53
,y.Short_Description54
,y.Data54
,y.Short_Description55
,y.Data55
,y.Short_Description56
,y.Data56
,y.Short_Description57
,y.Data57
,y.Short_Description58
,y.Data58
,y.Short_Description59
,y.Data59
,y.Short_Description60
,y.Data60
,y.Short_Description61
,y.Data61
,y.Short_Description62
,y.Data62
,y.Short_Description63
,y.Data63
,y.Short_Description64
,y.Data64
,y.Short_Description65
,y.Data65
,y.Short_Description66
,y.Data66
,y.Short_Description67
,y.Data67
,y.Short_Description68
,y.Data68
,y.Short_Description69
,y.Data69
,y.Short_Description70
,y.Data70
,y.Short_Description71
,y.Data71
,y.Short_Description72
,y.Data72
,y.Short_Description73
,y.Data73
,y.Short_Description74
,y.Data74
,y.Short_Description75
,y.Data75
,y.Short_Description76
,y.Data76
,y.Short_Description77
,y.Data77
,y.Short_Description78
,y.Data78
,y.Short_Description79
,y.Data79
,y.Short_Description80
,y.Data80
,y.Short_Description81
,y.Data81
,y.Short_Description82
,y.Data82
,y.Short_Description83
,y.Data83
,y.Short_Description84
,y.Data84
,y.Short_Description85
,y.Data85
,y.Short_Description86
,y.Data86
,y.Short_Description87
,y.Data87
,y.Short_Description88
,y.Data88
,y.Short_Description89
,y.Data89
,y.Short_Description90
,y.Data90
,y.Short_Description91
,y.Data91
,y.Short_Description92
,y.Data92
,y.Short_Description93
,y.Data93
,y.Short_Description94
,y.Data94
,y.Short_Description95
,y.Data95
,y.Short_Description96
,y.Data96
,y.Short_Description97
,y.Data97
,y.Short_Description98
,y.Data98
,y.Short_Description99
,y.Data99
,y.Short_Description100
,y.Data100
,x.rownum
FROM qryIndividualTestData100Descriptions AS x
INNER JOIN individualtestdata100 AS y ON (x.Short_Description100 =
y.Short_Description100)
AND (x.Short_Description99 = y.Short_Description99)
AND (x.Short_Description98 = y.Short_Description98)
AND (x.Short_Description97 = y.Short_Description97)
AND (x.Short_Description96 = y.Short_Description96)
AND (x.Short_Description95 = y.Short_Description95)
AND (x.Short_Description94 = y.Short_Description94)
AND (x.Short_Description93 = y.Short_Description93)
AND (x.Short_Description92 = y.Short_Description92)
AND (x.Short_Description91 = y.Short_Description91)
AND (x.Short_Description90 = y.Short_Description90)
AND (x.Short_Description89 = y.Short_Description89)
AND (x.Short_Description88 = y.Short_Description88)
AND (x.Short_Description87 = y.Short_Description87)
AND (x.Short_Description86 = y.Short_Description86)
AND (x.Short_Description85 = y.Short_Description85)
AND (x.Short_Description84 = y.Short_Description84)
AND (x.Short_Description83 = y.Short_Description83)
AND (x.Short_Description82 = y.Short_Description82)
AND (x.Short_Description81 = y.Short_Description81)
AND (x.Short_Description80 = y.Short_Description80)
AND (x.Short_Description79 = y.Short_Description79)
AND (x.Short_Description78 = y.Short_Description78)
AND (x.Short_Description77 = y.Short_Description77)
AND (x.Short_Description76 = y.Short_Description76)
AND (x.Short_Description75 = y.Short_Description75)
AND (x.Short_Description74 = y.Short_Description74)
AND (x.Short_Description73 = y.Short_Description73)
AND (x.Short_Description72 = y.Short_Description72)
AND (x.Short_Description71 = y.Short_Description71)
AND (x.Short_Description70 = y.Short_Description70)
AND (x.Short_Description69 = y.Short_Description69)
AND (x.Short_Description68 = y.Short_Description68)
AND (x.Short_Description67 = y.Short_Description67)
AND (x.Short_Description66 = y.Short_Description66)
AND (x.Short_Description65 = y.Short_Description65)
AND (x.Short_Description64 = y.Short_Description64)
AND (x.Short_Description63 = y.Short_Description63)
AND (x.Short_Description62 = y.Short_Description62)
AND (x.Short_Description61 = y.Short_Description61)
AND (x.Short_Description60 = y.Short_Description60)
AND (x.Short_Description59 = y.Short_Description59)
AND (x.Short_Description58 = y.Short_Description58)
AND (x.Short_Description57 = y.Short_Description57)
AND (x.Short_Description56 = y.Short_Description56)
AND (x.Short_Description55 = y.Short_Description55)
AND (x.Short_Description54 = y.Short_Description54)
AND (x.Short_Description53 = y.Short_Description53)
AND (x.Short_Description52 = y.Short_Description52)
AND (x.Short_Description51 = y.Short_Description51)
AND (x.Short_Description50 = y.Short_Description50)
AND (x.Short_Description49 = y.Short_Description49)
AND (x.Short_Description48 = y.Short_Description48)
AND (x.Short_Description47 = y.Short_Description47)
AND (x.Short_Description46 = y.Short_Description46)
AND (x.Short_Description45 = y.Short_Description45)
AND (x.Short_Description44 = y.Short_Description44)
AND (x.Short_Description43 = y.Short_Description43)
AND (x.Short_Description42 = y.Short_Description42)
AND (x.Short_Description41 = y.Short_Description41)
AND (x.Short_Description40 = y.Short_Description40)
AND (x.Short_Description39 = y.Short_Description39)
AND (x.Short_Description38 = y.Short_Description38)
AND (x.Short_Description37 = y.Short_Description37)
AND (x.Short_Description36 = y.Short_Description36)
AND (x.Short_Description35 = y.Short_Description35)
AND (x.Short_Description34 = y.Short_Description34)
AND (x.Short_Description33 = y.Short_Description33)
AND (x.Short_Description32 = y.Short_Description32)
AND (x.Short_Description31 = y.Short_Description31)
AND (x.Short_Description30 = y.Short_Description30)
AND (x.Short_Description29 = y.Short_Description29)
AND (x.Short_Description28 = y.Short_Description28)
AND (x.Short_Description27 = y.Short_Description27)
AND (x.Short_Description26 = y.Short_Description26)
AND (x.Short_Description25 = y.Short_Description25)
AND (x.Short_Description24 = y.Short_Description24)
AND (x.Short_Description23 = y.Short_Description23)
AND (x.Short_Description22 = y.Short_Description22)
AND (x.Short_Description21 = y.Short_Description21)
AND (x.Short_Description20 = y.Short_Description20)
AND (x.Short_Description19 = y.Short_Description19)
AND (x.Short_Description18 = y.Short_Description18)
AND (x.Short_Description17 = y.Short_Description17)
AND (x.Short_Description16 = y.Short_Description16)
AND (x.Short_Description15 = y.Short_Description15)
AND (x.Short_Description14 = y.Short_Description14)
AND (x.Short_Description13 = y.Short_Description13)
AND (x.Short_Description12 = y.Short_Description12)
AND (x.Short_Description11 = y.Short_Description11)
AND (x.Short_Description10 = y.Short_Description10)
AND (x.Short_Description9 = y.Short_Description9)
AND (x.Short_Description8 = y.Short_Description8)
AND (x.Short_Description7 = y.Short_Description7)
AND (x.Short_Description6 = y.Short_Description6)
AND (x.Short_Description5 = y.Short_Description5)
AND (x.Short_Description4 = y.Short_Description4)
AND (x.Short_Description3 = y.Short_Description3)
AND (x.Short_Description2 = y.Short_Description2)
AND (x.Short_Description1 = y.Short_Description1)
WHERE (
((y.Part_Number) LIKE [pn] & "*" & [tt])
AND (
(y.Serial_Number) >= [sns]
AND (y.Serial_Number) <= [sne]
)
AND (
(y.Test_Date) >= [ds]
AND (y.Test_Date) <= [de]
)
);
Why does access choke on the query?

Updating multiple tables inside cursor not working

I have two records in a table A. This helps me to update table 2 however the update is not been applied. This is the SQL code where I added a validation section that allow me to determinate the problem.
DECLARE abc CURSOR FOR
select d.cod_suc, d.cod_ramo_comercial, d.nro_pol, d.cod_item, d.cod_ramo_tecnico, d.cod_tarifa,
d.id_stro, d.nro_stro, d.fec_hora_reclamo, d.fec_aviso, d.fec_registro, d.fec_ingreso_contable,
d.txt_place_of_accident, d.id_substro, d.txt_nombre_cober, d.txt_direccion_bien_siniestrado, d.txt_descripcion_perdida, d.txt_cheque_a_nom, d.cod_manager_code, d.importe_pago_eq
from table1 d
where d.fec_hora_reclamo between '20140801' and '20150731'
and (d.cod_suc = 2 and d.cod_ramo_comercial = 255 and d.nro_pol = 1000001 and d.cod_item = 5)
OPEN abc
FETCH abc INTO #cod_suc, #cod_ramo_comercial, #nro_pol, #cod_item, #cod_ramo_tecnico, #cod_tarifa,
#id_stro, #nro_stro, #fec_hora_reclamo, #fec_aviso, #fec_registro, #fec_ingreso_contable,
#txt_place_of_accident, #id_substro, #txt_nombre_cober, #txt_direccion_bien_siniestrado, #txt_descripcion_perdida, #txt_cheque_a_nom, #cod_manager_code, #importe_pago_eq
WHILE (##FETCH_STATUS = 0)
BEGIN
select #varIDPV = min(id_pv), #varCodTarifa = min(cod_tarifa)
from #portfolio p
where p.cod_suc = #cod_suc and p.cod_ramo_comercial = #cod_ramo_comercial and p.Poliza = #nro_pol and p.Item = #cod_item and p.cod_ramo_tecnico = #cod_ramo_tecnico
and p.[ID Incident] IS NULL
/**************************************************************************************************************
-- Validation section
-- First record:
mid(id_pv) = 100, min(cod_tarifa) = 1
-- Second record:
mid(id_pv) = 100, min(cod_tarifa) = 1
--> Should be mid(id_pv) = 100, min(cod_tarifa) = 2
*/
select min(id_pv), min(cod_tarifa)
from #portfolio p
where p.cod_suc = #cod_suc and p.cod_ramo_comercial = #cod_ramo_comercial and p.Poliza = #nro_pol and p.Item = #cod_item and p.cod_ramo_tecnico = #cod_ramo_tecnico
and p.[ID Incident] IS NULL
/**************************************************************************************************************/
update p set p.[ID Incident] = #id_stro, p.[No. Incident] = #nro_stro,
p.[Fecha Accidente] = #fec_hora_reclamo, p.[Fecha Notificacion] = #fec_aviso, p.[Fecha Registro] = #fec_registro, p.[Fecha Pago] = #fec_ingreso_contable,
p.[Lugar Accidente] = #txt_place_of_accident, p.[ID Subsiniestro] = #id_substro, p.[Cobertura Amparo] = #txt_nombre_cober, p.[Direccion Bien Siniestrado] = #txt_direccion_bien_siniestrado, p.[Descripcion Perdida] = #txt_descripcion_perdida, p.[Pago A] = #txt_cheque_a_nom, p.[Referida] = #cod_manager_code,
[Incurrido R12] = #importe_pago_eq, [Incurrido Cerrados R12] = #importe_pago_eq
from #portfolio p
where p.cod_suc = #cod_suc and p.cod_ramo_comercial = #cod_ramo_comercial and p.Poliza = #nro_pol and p.Item = #cod_item and p.cod_ramo_tecnico = #cod_ramo_tecnico
and p.[ID Incident] IS NULL and p.id_pv = #varIDPV and p.cod_tarifa = #varCodTarifa
FETCH abc INTO #cod_suc, #cod_ramo_comercial, #nro_pol, #cod_item, #cod_ramo_tecnico, #cod_tarifa,
#id_stro, #nro_stro, #fec_hora_reclamo, #fec_aviso, #fec_registro, #fec_ingreso_contable,
#txt_place_of_accident, #id_substro, #txt_nombre_cober, #txt_direccion_bien_siniestrado, #txt_descripcion_perdida, #txt_cheque_a_nom, #cod_manager_code, #importe_pago_eq
END
CLOSE abc
DEALLOCATE abc
When I see the result, only the first record is updated.
I found the problem. I forgot to add one condition more in update (inside where). Thanks for the support

My SQL query is only returning children I need the parent aswell

My sql query is only returning the children of the parent I need it to return the parent as well,
public function getNav($cat,$subcat){
//gets all sub categories for a specific category
if(!$this->checkValue($cat)) return false; //checks data
$query = false;
if($cat=='NULL'){
$sql = "SELECT itemID, title, parent, url, description, image
FROM p_cat
WHERE deleted = 0
AND parent is NULL
ORDER BY position;";
$query = $this->db->query($sql) or die($this->db->error);
}else{
//die($cat);
$sql = "SET #parent = (SELECT c.itemID FROM p_cat c WHERE url = '".$this->sql($cat)."' AND deleted = 0);
SELECT c1.itemID, c1.title, c1.parent, c1.url, c1.description, c1.image, (SELECT c2.url FROM p_cat c2 WHERE c2.itemID = c1.parent LIMIT 1) as parentUrl
FROM p_cat c1
WHERE c1.deleted = 0
AND c1.parent = #parent
ORDER BY c1.position;";
$query = $this->db->multi_query($sql) or die($this->db->error);
$this->db->store_result(); $this->db->next_result();
$query = $this->db->store_result();
}
return $query;
}
may be:
"SET #parent = (SELECT c.itemID FROM p_cat c WHERE url = '".$this->sql($cat)."' AND deleted = 0);
SELECT c1.itemID, c1.title, c1.parent, c1.url, c1.description, c1.image, (SELECT c2.url FROM p_cat c2 WHERE c2.itemID = c1.parent LIMIT 1) as parentUrl
FROM p_cat c1
WHERE c1.deleted = 0
AND (c1.parent = #parent OR c1.itemID = #parent)
ORDER BY c1.position;"
Just join the p_cat table back to itself:
SELECT c1.itemID, c1.title, c1.parent, c1.url, c1.description, c1.image
, parents.itemID, parents.parent, parents.url, parents.description, parents.image,
FROM p_cat c1
Inner Join p_cat parents
On parents.id = C1.parent
WHERE c1.deleted = 0
AND c1.parent = #parent
ORDER BY c1.position