how to delete automatic date if more than 5 minutes using codeigniter - codeigniter-3

how to delete automatic date if more than 5 minutes
$time = 1;
$deletetoken = "DELETE FROM log aa LEFT JOIN user bb ON aa.`email`=bb.`email`
WHERE aa.`code_aktivasi`='code_aktivasi'
DATEDIFF(CURDATE(), create_at)-> $time";
$run = mysql_query($deletetoken);
I want automatic date if more than 5 minutes,
But it is not working, what might be happening?

Here's my suggestion, hoping it helps you to solve the problem.
$sql = "DELETE FROM log l LEFT JOIN user u ON l.`email`= u.`email`
WHERE l.`code_aktivasi`='code_aktivasi' and `create_at` < (NOW() - INTERVAL 5 MINUTE)";
$run = mysql_query($sql);
You can use l.create_at or u.create_at for matching your purpose.
If it's still not working, please show me the error message.

Related

Optimizing Postgres query with timestamp filter

I have a query:
SELECT DISTINCT ON (analytics_staging_v2s.event_type, sent_email_v2s.recipient, sent_email_v2s.sent) sent_email_v2s.id, sent_email_v2s.user_id, analytics_staging_v2s.event_type, sent_email_v2s.campaign_id, sent_email_v2s.recipient, sent_email_v2s.sent, sent_email_v2s.stage, sent_email_v2s.sequence_id, people.role, people.company, people.first_name, people.last_name, sequences.name as sequence_name
FROM "sent_email_v2s"
LEFT JOIN analytics_staging_v2s ON sent_email_v2s.id = analytics_staging_v2s.sent_email_v2_id
JOIN people ON sent_email_v2s.person_id = people.id
JOIN sequences on sent_email_v2s.sequence_id = sequences.id
JOIN users ON sent_email_v2s.user_id = users.id
WHERE "sent_email_v2s"."status" = 1
AND "people"."person_type" = 0
AND (sent_email_v2s.sequence_id = 1888) AND (sent_email_v2s.sent >= '2016-03-18')
AND "users"."team_id" = 1
When I run EXPLAIN ANALYZE on it, I get:
Then, if I change that to the following (Just removing the (sent_email_v2s.sent >= '2016-03-18')) as follows:
SELECT DISTINCT ON (analytics_staging_v2s.event_type, sent_email_v2s.recipient, sent_email_v2s.sent) sent_email_v2s.id, sent_email_v2s.user_id, analytics_staging_v2s.event_type, sent_email_v2s.campaign_id, sent_email_v2s.recipient, sent_email_v2s.sent, sent_email_v2s.stage, sent_email_v2s.sequence_id, people.role, people.company, people.first_name, people.last_name, sequences.name as sequence_name
FROM "sent_email_v2s"
LEFT JOIN analytics_staging_v2s ON sent_email_v2s.id = analytics_staging_v2s.sent_email_v2_id
JOIN people ON sent_email_v2s.person_id = people.id
JOIN sequences on sent_email_v2s.sequence_id = sequences.id
JOIN users ON sent_email_v2s.user_id = users.id
WHERE "sent_email_v2s"."status" = 1
AND "people"."person_type" = 0
AND (sent_email_v2s.sequence_id = 1888) AND "users"."team_id" = 1
when I run EXPLAIN ANALYZE on this query, the results are:
EDIT:
The results above from today are about as I expected. When I ran this last night, however, the difference created by including the timestamp filter was about 100x slower (0.5s -> 59s). The EXPLAIN ANALYZE from last night showed all of the time increase to be attributed to the first unique/sort operation in the query plan above.
Could there be some kind of caching issue here? I am worried now that there might be something else going on (transiently) that might make this query take 100x longer since it happened at least once.
Any thoughts are appreciated!

Select data within specific month in SELECT-OPTIONS

This ABAP code works but it works only once. I run this code with different parameters but result data does not change. How can I solve it?
PARAMETERS : S_MONTH LIKE ISELLIST-MONTH OBLIGATORY.
SELECT-OPTIONS : S_DATE FOR SY-DATUM.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_MONTH.
PERFORM GET_DATES.
FORM GET_DATES.
DATA: MONTH LIKE ISELLIST-MONTH,
FIRST_DAY LIKE SY-DATUM,
LAST_DAY LIKE SY-DATUM.
MONTH = SY-DATUM+0(6). "default
CALL FUNCTION 'POPUP_TO_SELECT_MONTH'
EXPORTING
ACTUAL_MONTH = MONTH
IMPORTING
SELECTED_MONTH = MONTH.
IF SY-SUBRC <> 0.
"put some message
ENDIF.
CONCATENATE MONTH '01' INTO FIRST_DAY.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = FIRST_DAY
IMPORTING
LAST_DAY_OF_MONTH = LAST_DAY.
IF SY-SUBRC <> 0.
"put some message
ENDIF.
S_DATE-LOW = FIRST_DAY.
S_DATE-HIGH = LAST_DAY.
S_DATE-SIGN = 'I'.
S_DATE-OPTION = 'BT'.
APPEND S_DATE.
S_MONTH = MONTH.
ENDFORM.
Add REFRESH S_DATE. before the APPEND S_DATE. You are now just appending every selection you make.

For each loop for a table in OpenEdge 10.2b takes more time

Below for each loop takes more time and i cant able to trace index usage using XREF as the table uses Oracle Schema.Please Help me.
Need to generate report for different Report Type ( Report type is the input parameter in my code ).Single report type may contain more than 50,000 records how to access all the record within minute.Index detail also mentioned below for each loop.
FOR EACH Report
FIELDS(EXTRACTDATE STATUS MailingType ReportType ReportNumber
RequestID CustID)
WHERE Report.EXTRACTDATE < Today
AND Report.ReportType = 'Customer Report'
AND Report.STATUS = 'Pending'
AND (Report.MailingType = "LETTER"
OR Report.MailingType = "Mail") NO-LOCK:
< Statements >
.
.
END.
**Index Detail**
CREATE INDEX "TYPE_IDX1" ON "Report" ("EXTRACTDATE" DESC, "ReportTYPE", "STATUS", "MailingTYPE", "PROGRESS_RECID")
CREATE INDEX "REQ_IDX1" ON "Report" ("REQUESTID", "PROGRESS_RECID")
CREATE INDEX "RTTYP_IDX1" ON "Report" ("ReportTYPE","PROGRESS_RECID")
The "OR" at the end will slow things down considerably - the AVM does better if you split it up into two sets of AND statements and OR the result, like so:
WHERE (Report.EXTRACTDATE < Today
AND Report.ReportType = 'Customer Report'
AND Report.STATUS = 'Pending'
AND Report.MailingType = "LETTER")
OR
(Report.EXTRACTDATE < Today
AND Report.ReportType = 'Customer Report'
AND Report.STATUS = 'Pending'
AND Report.MailingType = "Mail")

Add record to table, and edit records in 2 separate tables

Hi there I'm making an access database, and I can't figure out how to do one particular thing.
I've got a form with two text boxes: MovieID and CustomerID. I also have three separate tables: MovieList, CustomerInfo and HireHistory. What I need is so that when I enter a MovieID and CustomerID into the given boxes then press my button HireButton, it edits that specific MovieID's LastHireDate to Today(), edits that specific CustomerID's LastHireDate to Today(), and then in my HireForm (which has the CustomerID's in the first row) it adds a new record below the CustomerID in the form of: MovieID " on " Today()
Also, I need to make it so that it checks that MovieID's genre and if it's R16 or R18, then it checks whether the customer is older than 16 or 18 today, and if not then it comes up with an error box. I know how to do the checking whether they are older than 16 or 18, but not the error box.
I know that's a lot of text, so I'll just write what's in my brain (how I see the code should be) so it will be easier to see what I want to do.
IF MovieID.Rating = 'R16' OR 'R18'
THEN IF CustomerID.[Date(Year(DOB)+16,Month(DOB),(Day(DOB))] > Today()
THEN DISPLAY Msgbox = "Sorry, too young"
ELSE SET CustomerID.LastHireDate = Today()
SET MovieID.LastHireDate = Today()
ADDRECORD in HireHistory for that CustomerID to (MovieID & " on " & Today())
ELSE SET CustomerID.LastHireDate = Today()
SET MovieID.LastHireDate = Today()
ADDRECORD in HireHistory for that CustomerID to (MovieID & " on " & Today())
Does that explain it a bit better? Thanks in advance for your help! :)
so here How I would do this. You first have to create a recordset for each of those table.
For the age I would use this function. : http://www.fmsinc.com/MicrosoftAccess/modules/examples/AgeCalculation.asp
customerBirth = yourCode to get the date
If MovieID.Rating = 'R16' OR 'R18' then
If AgeYears(customerBirth) < 16 then
msgbox("Sorry, too young")
else
MyCustomerRecordSet("LastHireDate") = now
MyMovieRecordSet("LastHireDate") = now
MyHireRecorset.AddNew
MyHireRecorset("I don't know what your trying to do here")
MyHireRecorset.Update
end if
Else
MyCustomerRecordSet("LastHireDate") = now
MyMovieRecordSet("LastHireDate") = now
MyHireRecorset.AddNew
MyHireRecorset("I don't know what your trying to do here")
End if
If you have any question just ask.

DB2 V9 ZOS - Performance tuning

Background
Currently I am using DB2 V9 version. One of my stored procedure is taking time to execute. I looked BMC apptune and found the following SQL.
There are three tables we were using to execute the following query.
ACCOUNT table is having 3413 records
EXCHANGE_RATE is having 1267K records
BALANCE is having 113M records
Someone has added recently following piece of code in the query. I think because of this we had a problem.
AND (((A.ACT <> A.EW_ACT)
AND (A.EW_ACT <> ' ')
AND (C.ACT = A.EW_ACT))
OR (C.ACT = A.ACT))
Query
SELECT F1.CLO_LED
INTO :H :H
FROM (SELECT A.ACT, A.BNK, A.ACT_TYPE,
CASE WHEN :H = A.CUY_TYPE THEN DEC(C.CLO_LED, 21, 2)
ELSE DEC(MULTIPLY_ALT(C.CLO_LED, COALESCE(B.EXC_RATE, 0)), 21, 2)
END AS CLO_LED
FROM ACCOUNT A
LEFT OUTER JOIN EXCHANGE_RATE B
ON B.EFF_DATE = CURRENT DATE - 1 DAY
AND B.CURCY_FROM = A.CURNCY_TYPE
AND B.CURCY_TO = :H
AND B.STA_TYPE = 'A'
, BALANCE C
WHERE A.CUSR_ID = :DCL.CUST-ID
AND A.ACT = :DCL.ACT
AND A.EIG_RTN = :WS-BNK-ID
AND A.ACT_TYPE = :DCL.ACT-TYPE
AND A.ACT_CAT = :DCL.ACT-CAT
AND A.STA_TYPE = 'A'
AND (((A.ACT <> A.EW_ACT)
AND (A.EW_ACT <> ' ')
AND (C.ACT = A.EW_ACT))
OR (C.ACT = A.ACT))
AND C.BNK = :WS-BNK-ID
AND C.ACT_TYPE = :DCL.ACT-TYPE
AND C.BUS_DATE = :WS-DATE-FROM) F1
WITH UR
There's a number of wierd things going on in this query. The most twitchy of which is mixing explicit joins with the implicit-join syntax; frankly, I'm not certain how the system interprets it. You also appear to be using the same host-variable for both input and output; please don't.
Also, why are your column names so short? DB2 (that version, at least) supports column names that are much longer. Please save people's sanity, if at all possible.
We can't completely say why things are slow - we may need to see access plans. In the meantime, here's your query, restructured to what may be a faster form:
SELECT CASE WHEN :inputType = a.cuy_type THEN DEC(b.clo_led, 21, 2)
ELSE DEC(MULTIPLY_ALT(b.clo_led, COALESCE(c.exc_rate, 0)), 21, 2) END
INTO :amount :amountIndicator -- if you get results, do you need the indiciator?
FROM Account as a
JOIN Balance as b -- This is assumed to not be a 'left', given coalesce not used
ON b.bnk = a.eig_rtn
AND b.act_type = a.act_type
AND b.bus_date = :ws-date-from
AND ((a.act <> a.ew_act -- something feels wrong here, but
AND a.ew_act <> ' ' -- without knowing the data, I don't
AND c.act = a.ew_act) -- want to muck with it.
OR c.act = a.act)
LEFT JOIN Exchange_Rate as c
ON c.eff_date = current_date - 1 day
AND c.curcy_from = a.curncy_type
AND c.sta_type = a.sta_type
AND c.curcy_to = :destinationCurrency
WHERE a.cusr_id = :dcl.cust-id
AND a.act = :dcl.act
AND a.eig_rtn = :ws-bnk-id
AND a.act_type = :dcl.act-type
AND a.act_cat = :dcl.act-cat
AND a.sta_type = 'A'
WITH UR
FECTCH FIRST 1 ROW ONLY
A few other notes:
Only specify exactly those columns needed - under certain circumstances, this permits index-only access, where otherwise a followup table-access may be needed. However, this probably won't help here.
COALESCE(c.exc_rate, 0) feels off somehow - if no exchange rate is present, you return an amount of 0, which could otherwise be a valid amount. You may need to return some sort of indicator, or make it a normal join, not an outer one.
Also, try both this version, and possibly a version where host variables are specified in addition to the conditions between tables. The optimizer should be able to automatically commute the values, but may not under some conditions (implementation detail).