Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8180727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:16:54+00:00 2026-06-07T00:16:54+00:00

I have come across an annoying problem. I have made a system and now

  • 0

I have come across an annoying problem.

I have made a system and now users are telling me that it is giving them the message:

Out of memory (Needed 268435427 bytes)

The entire database is 12MB in size and the query that is having the problem has ran fine for several months and isn’t really that complex or large.

The database is innodb. My server has 24GB of ram so I seriously doubt it is actually out of memory.

my.cnf is as follows:

key_buffer = 8000M

max_allowed_packet = 1M

table_cache = 2048M

sort_buffer_size = 1M

net_buffer_length = 1024M

read_buffer_size = 1M

read_rnd_buffer_size = 24M

innodb_log_file_size = 5M

innodb_log_buffer_size = 8M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 50

innodb_buffer_pool_size = 1024M

innodb_additional_mem_pool_size = 2M

max_connections = 100

query_cache_size = 128M

query_cache_min_res_unit = 1024

query_cache_limit = 16MB

thread_cache_size = 100

max_heap_table_size = 4096MB

When looking in windows task manager I am seeing 18.8GB available but with only 100MB free. It is Windows 2008 64bit Server, could this be the source of the problem?


Here is the query:

$currency     = '(SELECT currencies.symbol
                            FROM parts_trading, currencies
                            WHERE parts_trading.enquiryRef = enquiries.id
                            AND parts_trading.sellingCurrency = currencies.id
                            LIMIT 1
                         )' ;

$amountDueSQL = '(
                         (SELECT SUM(quantity*(parts_trading.sellingNet
                                    +
                                    parts_trading.sellingVat))
                            FROM parts_trading
                            WHERE parts_trading.enquiryRef = enquiries.id
                         )
                         +
                         (SELECT SUM(enquiries_custom_fees.feeAmountNet
                                    +
                                    enquiries_custom_fees.feeAmountVat)
                            FROM enquiries_custom_fees
                            WHERE enquiries_custom_fees.enquiryRef = enquiries.id
                         )
                         )' ;
$amountPaidSQL = 'COALESCE(
                             (SELECT SUM(jobs_payments_advance.amount)
                                FROM jobs_payments_advance
                                WHERE jobs_payments_advance.jobRef = jobs.id
                             ),
                             0
                         )' ;

    $result = $dbh->prepare("SELECT SQL_CALC_FOUND_ROWS jobs.id, jobs_states.state, jobs.creationDate, users.username,
                            entity_details.name, enquiries.id as enquiryId, pendingCancelation,
                            IF(entity_details.paymentTermsRef = 1, # Outer IF condition
                               IF($amountDueSQL-$amountPaidSQL = 0.00, # Inner IF condition
                                  CONCAT('Paid in full (', $currency, $amountDueSQL, ')') # Inner IF TRUE
                               , # End of inner IF TRUE
                                  IF($amountPaidSQL > 0,
                                     CONCAT('Part paid (', $currency, $amountPaidSQL, ')'),
                                     'Unpaid'
                                  )
                               ) # End of inner IF

                            , # End of TRUE for outer IF
                               (SELECT entity_payment_terms.term
                                    FROM entity_details, entity_payment_terms
                                    WHERE entity_details.paymentTermsRef
                                          =
                                          entity_payment_terms.id
                                    AND entity_details.id = enquiries.entityRef
                               ) # End of FALSE for outer IF
                            ) AS payState, enquiries.orderNumber,

                            IF((SELECT COUNT(*)
                                    FROM invoices_out, (SELECT * FROM invoices_out_reference GROUP BY jobRef) AS tb1
                             WHERE invoices_out.id = tb1.invoiceRef
                             AND tb1.jobRef = jobs.id) > 1,
                               'Part-invoiced',
                               (SELECT invoices_out.date
                                    FROM invoices_out, (SELECT * FROM invoices_out_reference GROUP BY jobRef) AS tb1
                             WHERE invoices_out.id = tb1.invoiceRef
                             AND tb1.jobRef = jobs.id)
                             ) AS invoicedDate,

                            enquiries.id AS enquiryId,

                            IF((SELECT COUNT(*)
                                    FROM invoices_out, (SELECT * FROM invoices_out_reference GROUP BY jobRef) AS tb1
                             WHERE invoices_out.id = tb1.invoiceRef
                             AND tb1.jobRef = jobs.id) > 1,
                               'Multiple invoices',
                               (SELECT invoices_out.id
                                    FROM invoices_out, (SELECT * FROM invoices_out_reference GROUP BY jobRef) AS tb1
                             WHERE invoices_out.id = tb1.invoiceRef
                             AND tb1.jobRef = jobs.id)
                             ) AS invoiceNumber,

                            # If the state is 0 (i.e. they have an account, if true find out their payment terms, if false, instead reference the payment state directly.
                            (SELECT MAX(etaDate) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) AS maxEtaDate,
                            (SELECT COUNT(DISTINCT DATE(etaDate)) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) AS etaCounts, entity_credit_limits.creditLimit AS cLimit,
                            COALESCE((SELECT 
                                    SUM(qty*parts_trading_buying.buyingNet
                                    /
                                    (SELECT rateVsPound FROM currencies WHERE currencies.id = parts_trading_buying.buyingCurrency))
                                    FROM parts_trading_buying
                                    WHERE parts_trading_buying.enquiryRef = enquiries.id
                                    ), 0
                                    ) AS nonInvoicedBuyingCosts,
                            COALESCE((SELECT 
                                    SUM(feeAmountNet/(SELECT rateVsPound FROM currencies WHERE currencies.id = parts_trading_buying.buyingCurrency))
                                    FROM parts_trading_buying_charges, parts_trading_buying 
                                    WHERE parts_trading_buying_charges.partRef = parts_trading_buying.id
                                    AND parts_trading_buying.enquiryRef = enquiries.id
                                    ), 0
                                ) AS nonInvoicedBuyingFeeCosts,
                            (SELECT
                                SUM(quantity*parts_trading.sellingNet)
                                    /
                                    COALESCE(
                                        (SELECT invoices_out.rate
                                         FROM invoices_out, invoices_out_reference
                                         WHERE invoices_out.id = invoices_out_reference.invoiceRef
                                         AND invoices_out_reference.jobRef = jobs.id
                                         LIMIT 1),
                                        (SELECT rateVsPound
                                         FROM currencies
                                         WHERE currencies.id = parts_trading.sellingCurrency)
                                    )
                             FROM parts_trading
                             WHERE parts_trading.enquiryRef = enquiries.id
                            ) AS sellingParts,
                            COALESCE((SELECT
                                    SUM(enquiries_custom_fees.feeAmountNet)
                                    /
                                    COALESCE(
                                        (SELECT rate
                                         FROM invoices_out, invoices_out_reference
                                         WHERE invoices_out.id = invoices_out_reference.invoiceRef
                                         AND invoices_out_reference.jobRef = jobs.id LIMIT 1),
                                        (SELECT rateVsPound
                                         FROM currencies
                                         WHERE currencies.id = parts_trading.sellingCurrency
                                         )
                                    )
                                    FROM enquiries_custom_fees, parts_trading
                                    WHERE enquiries_custom_fees.enquiryRef = enquiries.id
                                    AND parts_trading.enquiryRef = enquiries.id), 0) AS sellingFees,
                            COALESCE((SELECT
                                    SUM(parts_shipping_out.shippingOutCost)
                                    FROM parts_shipping_out, parts_shipping_arrival_dates, parts_shipping_v2
                                    WHERE parts_shipping_out.arrivalsRef = parts_shipping_arrival_dates.id
                                    AND parts_shipping_arrival_dates.shippingRef = parts_shipping_v2.id
                                    AND parts_shipping_v2.jobRef = jobs.id
                                    ), 0
                                ) AS actualShippingOutFromEua,
                            (SELECT

                                SUM(quantity*parts_trading.sellingNet)
                                    /
                                    COALESCE(
                                        (SELECT invoices_out.rate
                                         FROM invoices_out, invoices_out_reference
                                         WHERE invoices_out.id = invoices_out_reference.invoiceRef
                                         AND invoices_out_reference.jobRef = jobs.id
                                         LIMIT 1),
                                        (SELECT rateVsPound
                                         FROM currencies
                                         WHERE currencies.id = parts_trading.sellingCurrency)
                                    )
                                +
                                COALESCE((SELECT
                                    SUM(enquiries_custom_fees.feeAmountNet)
                                    /
                                    COALESCE(
                                        (SELECT rate
                                         FROM invoices_out, invoices_out_reference
                                         WHERE invoices_out.id = invoices_out_reference.invoiceRef
                                         AND invoices_out_reference.jobRef = jobs.id LIMIT 1),
                                        (SELECT rateVsPound
                                         FROM currencies
                                         WHERE currencies.id = parts_trading.sellingCurrency
                                         )
                                    )
                                    FROM enquiries_custom_fees
                                    WHERE enquiries_custom_fees.enquiryRef = enquiries.id), 0)
                                -
                                COALESCE((SELECT 
                                    SUM(qty*parts_trading_buying.buyingNet
                                    /
                                    (SELECT rateVsPound FROM currencies WHERE currencies.id = parts_trading_buying.buyingCurrency))
                                    FROM parts_trading_buying
                                    WHERE parts_trading_buying.enquiryRef = enquiries.id
                                    ), 0
                                    )
                                -
                                COALESCE((SELECT 
                                    SUM(feeAmountNet/(SELECT rateVsPound FROM currencies WHERE currencies.id = parts_trading_buying.buyingCurrency))
                                    FROM parts_trading_buying_charges, parts_trading_buying 
                                    WHERE parts_trading_buying_charges.partRef = parts_trading_buying.id
                                    AND parts_trading_buying.enquiryRef = enquiries.id
                                    ), 0
                                )
                                -
                                COALESCE((SELECT
                                    SUM(parts_shipping_out.shippingOutCost)
                                    FROM parts_shipping_out, parts_shipping_arrival_dates, parts_shipping_v2
                                    WHERE parts_shipping_out.arrivalsRef = parts_shipping_arrival_dates.id
                                    AND parts_shipping_arrival_dates.shippingRef = parts_shipping_v2.id
                                    AND parts_shipping_v2.jobRef = jobs.id
                                    ), 0
                                )
                                FROM parts_trading, parts_trading_buying
                                WHERE parts_trading.enquiryRef = enquiries.id
                                AND parts_trading_buying.counterpartRef = parts_trading.id
                            ) AS margin
                            FROM jobs,
                            jobs_states, enquiries, users, jobs_payment_status, entity_details
                            LEFT JOIN entity_credit_limits ON entity_details.id = entity_credit_limits.entityRef
                            WHERE jobs.stateRef = jobs_states.id
                            AND IF(paymentStateRef = 0, 1, (jobs_payment_status.id = jobs.paymentStateRef))
                            # ^ If true it causes a result for each payment state (i.e. 3), so we group on state below, shouldn't cause probs.
                            AND jobs.enquiryRef = enquiries.id
                            AND enquiries.entityRef = entity_details.id
                            AND users.id = enquiries.traderRef
                            AND enquiries.traderRef = ?
                                LIMIT ?, ?") ;

If I try setting PHP execution memory above 3.5GB Apache wont start (I’m using xampp). I must be using a 32-bit version of PHP? This is the same for the INNODB_BUFFER_POOL_SIZE, which I would like to be 14GB, but mysql won’t start if I do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:16:56+00:00Added an answer on June 7, 2026 at 12:16 am

    I don’t think that this is a database related problem becouse this kind of error (Out of memory (Needed 268435427 bytes)) most of the time throwed by PHP (infinite loop or something similar is maybe the problem).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across an annoying problem while writing some PHP4 code. I renamed
I have come across a somewhat annoying problem during a project. I created this
Im persisting my data in MVC3 and have come across an annoying problem: Lets
I have come across a problem that I cannot see to solve. I have
I have come across scripts that use: isset($_POST['submit']) as well as code that uses:
I have come across a strange problem which I would like to get your
I have come across what seems to be an annoying bug with asp.net UpdatePanels
I have come across a problem trying to pass some objects to a java
I have come across a strange problem with Zend_Framework, I can not load forms
I have come across this rule in YSlow for performance improvement that says that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.