Optimization procedure The execution of the MySQL cursor takes a long time

I have a MySQL procedure with a cursor. The example cursor query is given below

DECLARE cs CURSOR FOR
           (SELECT  a.mag_id FROM A a  WHERE
                a.creation_date BETWEEN (v_fromdate) AND (v_todate) 
                AND a.type_id IN (SELECT type_id FROM key2 WHERE   sessionId=v_sessionId)
                AND a.mag_id IN (SELECT magid FROM    key1 WHERE   sessionId=v_sessionId order by magid)
                )
     UNION
                (SELECT  b.combo_mag_id FROM B b 
                WHERE
                b.creation_date BETWEEN (v_fromdate) AND (v_todate) 
                AND b.type_id IN (SELECT type_id FROM    key2 WHERE   sessionId=v_sessionId)
                AND b.combo_mag_id IN (SELECT magid FROM    key1 WHERE   sessionId=v_sessionId order by magid)
                );

DECLARE
CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET v_cur_time = now();
SET v_cur_query = 'cursor';
OPEN cs;
SELECT timestampdiff(SECOND,v_cur_time,now()) into v_diff;
SELECT CONCAT('Current Query: ', v_cur_query, ' Time taken: ', v_diff); 

Both Table A and Table B have millions of records. I've created partitions in both tables with partition by area at creation date. For 3 months of a date range, it takes almost 4 minutes to execute the cursor. But when I tried to execute the same query in The MySQL Workbench Editor took only 22 seconds to set the parameters for the same date range. Can anyone tell me why it runs faster in an SQL editor, and since I need to use it in the stored procedure, is there a way to tweak it?

Why does the stored procedure need extra time to perform a normal query execution (MYSQL)?

I have a stored procedure that returns single, but takes more than 16 seconds to call it, but only 0.5 seconds if I do that by normal query.

method

    DELIMITER $$
DROP PROCEDURE IF EXISTS `local_db`.`getAllMatchedStockByCompany` $$
CREATE
    PROCEDURE `local_db`.`getAllMatchedStockByCompany`(
    IN Company_ID BIGINT(20)
    )
    BEGIN
        SELECT t1.*
    FROM ((SELECT t2.SRTitle,t2.UrlPart,t2.ScheduledTime,t2.Photo,TRIM(REPLACE(REPLACE(REPLACE(REPLACE(SUBSTRING_INDEX(REPLACE(fnStripTags(t2.SRDescription),' ',''),' ',
            30), 'rntrnrnt', ''),'rntrnt',''),'rnt',''),'’',''))AS Description, 'stock-research' AS from_tbl,t2.IsActive
           ,t2.CompanyID FROM t2
          ) UNION
          (SELECT t3.ReportTitle,t3.UrlPart,t3.CreatedDate,t3.ReportImage,TRIM(REPLACE(REPLACE(SUBSTRING_INDEX(REPLACE(fnStripTags(t3.Description),' ',''),' ',
                30),'rntrnt',''),''','`')),IF(t3.SpecialReport = 1,'special-report','report'),t3.IsActive
        ,t3.CompanyID FROM t3
          )
         ) t1
         WHERE CompanyID = Company_ID AND IsActive = 1
         ORDER BY ScheduledTime DESC;
    END$$

DELIMITER ;

The total execution time for this is 16 seconds at 1 line.
But if I use a query below

SELECT t1.*
    FROM ((SELECT t2.SRTitle,t2.UrlPart,t2.ScheduledTime,t2.Photo,TRIM(REPLACE(REPLACE(REPLACE(REPLACE(SUBSTRING_INDEX(REPLACE(fnStripTags(t2.SRDescription),' ',''),' ',
            30), 'rntrnrnt', ''),'rntrnt',''),'rnt',''),'’',''))AS Description, 'stock-research' AS from_tbl,t2.IsActive
           ,t2.CompanyID FROM t2
          ) UNION
          (SELECT t3.ReportTitle,t3.UrlPart,t3.CreatedDate,t3.ReportImage,TRIM(REPLACE(REPLACE(SUBSTRING_INDEX(REPLACE(fnStripTags(t3.Description),' ',''),' ',
                30),'rntrnt',''),''','`')),IF(t3.SpecialReport = 1,'special-report','report'),t3.IsActive
        ,t3.CompanyID FROM t3
          )
         ) t1
         WHERE CompanyID = 931 AND IsActive = 1
         ORDER BY ScheduledTime DESC;

It took only 0.5 to 1 seconds with one line.

Can any of you tell me why this happens or how I can improve my SP execution time?

Many thanks

Remote Code Execution over WAN

Suppose I'm on a computer behind a NAT and want to run an RCE exploit on another computer behind another NAT. (Note that no ports are forwarded to the victim's computer on its NAT.) Assuming I already know the target computer is vulnerable to this exploit) and hope for a shell, so if so, what changes need to be made the exploit is successful?

Intercept execution in SQL Server Management Studio

I'm trying to find a policy to catch query execution in SQL Server Management Studio.
For example: I want to check the query for WHERE Clause after clicking on the Execute button.
I have already created an add-on in VS19 with VSIX project.
Should I intercept a button click, or can this be done by intercepting inner SSMS commands?

Is appreciated with every advice.

python – I need to reduce the execution time of my code to check the data of 2 Apis

I'm new to Python. I've been given the task of checking the data from 2 APIs that provide similar data, but have a different format; H. Json and XML. I wrote the code, but the execution takes too long. I am not familiar with formatting and so on. Please help me here. (For security reasons, I exclude URLs and headers, etc.)

from openpyxl import load_workbook
from xml.etree import ElementTree
import json
import urllib.request
import requests

wb = load_workbook("CNIC.xlsx")
source = wb("Sheet1")
for cniclist in source('A'):
    cnic = cniclist.value
    url = "/%s" % cnic
    urlobj = urllib.request.urlopen(url)
    try:
        string = urlobj.read().decode('utf-8')
        json_obj = json.loads(string)
    except:
        print(urlobj.readlines())
    url2 = "url2"
    payload = "{}
    headers = {}
    response = requests.request("POST", url2, data=payload.format(cnic), headers=headers)
    tree = ElementTree.ElementTree(ElementTree.fromstring(response.text))

    json_message = (json_obj.get('Message'))
    if json_message == "Success":

        json_record = (json_obj.get('Records'))
        if json_record == 1:
            for item in json_obj.get('OutData'):
                json_acc = item.get('Accounts')('NoAccounts')
                print("No Of Accounts in Json Service is ", json_acc)

        elif json_record > 1:
            json_acc = 0
            for item in json_obj.get('OutData'):
                json_acc = item.get('Accounts')('NoAccounts')
                print("No Of Accounts in Json Service is ", json_acc)
        else:
            print("No JSON Records found")
        root = tree.getroot()
        count = 0
        xml_acc_no = ()
        for FCDB_BODY in root.findall("./FCDB_BODY/CUSTACCOUNT/ACCOUNT/ACCNO"):
            temp = FCDB_BODY.text
            xml_acc_no.append(temp)
            count += 1
        print("No Of Accounts in XML Service is ", str(count))

        # Checking Number of Accounts in both services
        if str(json_acc) == str(count):
            print("Number of Accounts are same in both services")
        elif str(json_acc) > str(count):
            print("Json Service has more accounts  ")
        else:
            print("XML Service has more accounts ")

        # Getting all data from Json Service
        for item1 in json_obj.get('OutData'):
            json_file_account = item1.get('Accounts')(
                'AccountList')  # Getting Accountlist details from jason service file

            json_accounts_list = ()
            for i in json_file_account:
                json_acc_no = i('ACC#')  # Getting Account Number from Json service file
                json_accounts_list.append(json_acc_no)

            json_title_list = ()
            for i in json_file_account:
                json_acc_title = i('TITLE')  # Getting Account title from Json service file
                json_title_list.append(json_acc_title)

            json_type_list = ()
            for i in json_file_account:
                json_account_type = i('STYPE')  # Getting Account type from Json service file
                json_type_list.append(json_account_type)

            json_desc_list = ()
            for i in json_file_account:
                json_account_desc = i('STPDESC')  # Getting Account description from Json service file
                if json_account_desc is not "":
                    json_desc_list.append(json_account_desc)
                else:
                    pass
            json_bal_list = ()
            for i in json_file_account:
                json_account_bal1 = i('ABAL')  # Getting Account balance from Json service file
                json_account_bal = int(json_account_bal1) / 100
                json_account_bal = ('%f' % json_account_bal).rstrip('0').rstrip('.')
                json_bal_list.append(str(json_account_bal))

        # Getting all data from Json Service
        xml_title_list = ()
        for j in root.findall("./FCDB_BODY/CUSTACCOUNT/ACCOUNT/ACCOUNTTITLE"):
            xml_acc_title = j.text
            xml_title_list.append(xml_acc_title)

        xml_type_list = ()
        for k in root.findall("./FCDB_BODY/CUSTACCOUNT/ACCOUNT/ACCOUNTTYPEDETAIL"):
            xml_acc_type = k.text
            xml_type_list.append(xml_acc_type)

        xml_desc_list = ()
        for l in root.findall("./FCDB_BODY/CUSTACCOUNT/ACCOUNT/ACCPRDDESC"):
            xml_acc_desc = l.text
            xml_desc_list.append(xml_acc_desc)

        xml_bal_list = ()
        for m in root.findall("./FCDB_BODY/CUSTACCOUNT/ACCOUNT/BAL_AVAIL"):
            xml_acc_bal = float(m.text)
            xml_acc_bal = ('%f' % xml_acc_bal).rstrip('0').rstrip('.')
            xml_bal_list.append(xml_acc_bal)

        # Checks for Account Number,Title, Type, Description and Balance
        acc_check = ((x for x in xml_acc_no if x not in json_accounts_list),
                     (x for x in json_accounts_list if x not in xml_acc_no))
        if len(acc_check(0)) or len(acc_check(1)):
            if len(acc_check(0)):
                print("Accounts which are unmatched in XML are ", acc_check(0))

            if len(acc_check(1)):
                print("Accounts which are unmatched in JSON are ", acc_check(1))
        else:
            print("No Unmatched Accounts found")

        title_check = ((y for y in xml_title_list if y not in json_title_list),
                       (y for y in json_title_list if y not in xml_title_list))
        if len(title_check(0)) or len(title_check(1)):
            if len(title_check(0)):
                print("Title which are unmatched in XML are ", title_check(0))

            if len(title_check(1)):
                print("Title which are unmatched in JSON are ", title_check(1))
        else:
            print("No Unmatched Title found")

        type_check = ((z for z in xml_type_list if z not in json_type_list),
                      (z for z in json_type_list if z not in xml_type_list))
        if len(type_check(0)) or len(type_check(1)):
            if len(type_check(0)):
                print("Type which are unmatched in XML are ", type_check(0))

            if len(type_check(1)):
                print("Type which are unmatched in JSON are ", type_check(1))
        else:
            print("No Unmatched type found")

        desc_check = ((q for q in xml_desc_list if q not in json_desc_list),
                      (q for q in json_desc_list if q not in xml_desc_list))
        if len(desc_check(0)) or len(title_check(1)):
            if len(desc_check(0)):
                print("Description which are unmatched in XML are ", desc_check(0))

            if len(desc_check(1)):
                print("Description which are unmatched in JSON are ", desc_check(1))
        else:
            print("No Unmatched Description found")
        balance_check = ((w for w in xml_bal_list if w not in json_bal_list),
                         (w for w in json_bal_list if w not in xml_bal_list))
        if len(balance_check(0)) or len(balance_check(1)):
            if len(balance_check(0)):
                print("Balance which are unmatched in XML are ", balance_check(0))

            if len(balance_check(1)):
                print("Balance which are unmatched in JSON are ", balance_check(1))
        else:
            print("No Unmatched Balance found")

        print("-----------------------------------")

    else:
        print("CNIC NOT FOUND in Json Service ")
    print("-----------------------------------")

Order execution is very important.

To a forex trade oThe orderly execution is very important. There are many brokers who make an inquiry when ordering on their platform. It is the most irritating thing in the trade. I had this problem with my previous broker. Then I decided to change my broker. Currently I am trading with XeroMarkets Broker. Now I am satisfied with your business execution. Trades are executed immediately without this being necessary.

Plugins – Query execution does not complete after activating Cloudflare

I have created a simple search plugin for Woocommerce and have two examples of the plugin in the following domain names: http://klaussongs.com/ https://www.moderndiamondco.com/diamond/

As you can see in the first http site, the plugin works well if you change the filters. but in the second I have added cloudflare ssl and somehow the search filters will not return any values ​​and empty the table. I should probably mention this as this is my suspicion of where the problem stems from. The way I've created this plugin is that I query all WC product specifications (title, price, attributes) all at once and save them in a variable and all the search is done in the frontend. So, when someone searches for something, no request is returned to the WC table database. Could this be the problem. or is it something I remove from Cloudflare or maybe SSL from the host provider? All help and opinions are appreciated in advance.